naeem-statistics-library 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.js +35 -0
- package/package.json +22 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mean = mean;
|
|
4
|
+
exports.median = median;
|
|
5
|
+
exports.mode = mode;
|
|
6
|
+
// Mean: sum of all values / count
|
|
7
|
+
function mean(numbers) {
|
|
8
|
+
if (numbers.length === 0)
|
|
9
|
+
throw new Error("Array is empty");
|
|
10
|
+
const sum = numbers.reduce((acc, val) => acc + val, 0);
|
|
11
|
+
return sum / numbers.length;
|
|
12
|
+
}
|
|
13
|
+
// Median: middle value when sorted
|
|
14
|
+
function median(numbers) {
|
|
15
|
+
if (numbers.length === 0)
|
|
16
|
+
throw new Error("Array is empty");
|
|
17
|
+
const sorted = [...numbers].sort((a, b) => a - b);
|
|
18
|
+
const mid = Math.floor(sorted.length / 2);
|
|
19
|
+
return sorted.length % 2 !== 0
|
|
20
|
+
? sorted[mid]
|
|
21
|
+
: (sorted[mid - 1] + sorted[mid]) / 2;
|
|
22
|
+
}
|
|
23
|
+
// Mode: most frequently occurring value(s)
|
|
24
|
+
function mode(numbers) {
|
|
25
|
+
if (numbers.length === 0)
|
|
26
|
+
throw new Error("Array is empty");
|
|
27
|
+
const freq = new Map();
|
|
28
|
+
for (const num of numbers) {
|
|
29
|
+
freq.set(num, (freq.get(num) || 0) + 1);
|
|
30
|
+
}
|
|
31
|
+
const maxFreq = Math.max(...freq.values());
|
|
32
|
+
return [...freq.entries()]
|
|
33
|
+
.filter(([_, count]) => count === maxFreq)
|
|
34
|
+
.map(([num]) => num);
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "naeem-statistics-library",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"build": "tsc"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"description": "",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^25.6.0",
|
|
20
|
+
"typescript": "^6.0.2"
|
|
21
|
+
}
|
|
22
|
+
}
|