@powfix/core-js 0.13.7 → 0.13.8
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.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Calc = void 0;
|
|
4
|
+
class Calc {
|
|
5
|
+
static average(...values) {
|
|
6
|
+
const length = values.length;
|
|
7
|
+
if (length === 0) {
|
|
8
|
+
return NaN;
|
|
9
|
+
}
|
|
10
|
+
let sum = 0;
|
|
11
|
+
for (let i = 0; i < length; ++i) {
|
|
12
|
+
sum += values[i];
|
|
13
|
+
}
|
|
14
|
+
return sum / length;
|
|
15
|
+
}
|
|
16
|
+
static median(...values) {
|
|
17
|
+
const len = values.length;
|
|
18
|
+
if (len === 0)
|
|
19
|
+
return NaN;
|
|
20
|
+
const sorted = values.slice().sort((a, b) => a - b); // O(n log n)
|
|
21
|
+
const mid = len >> 1;
|
|
22
|
+
return len % 2 === 0
|
|
23
|
+
? (sorted[mid - 1] + sorted[mid]) / 2
|
|
24
|
+
: sorted[mid];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.Calc = Calc;
|
|
@@ -20,6 +20,7 @@ __exportStar(require("./AxiosUtils"), exports);
|
|
|
20
20
|
__exportStar(require("./StringUtils"), exports);
|
|
21
21
|
__exportStar(require("./UuidUtils"), exports);
|
|
22
22
|
__exportStar(require("./BooleanUtils"), exports);
|
|
23
|
+
__exportStar(require("./Calc"), exports);
|
|
23
24
|
__exportStar(require("./CoordinateUtils"), exports);
|
|
24
25
|
__exportStar(require("./DateUtils"), exports);
|
|
25
26
|
__exportStar(require("./NumberUtils"), exports);
|