@numio/bigmath 1.0.9 → 1.0.10
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/README.md +43 -7
- package/index.d.ts +4 -2
- package/index.js +4 -2
- package/package.json +8 -2
- package/src/IQR/main.d.ts +2 -0
- package/src/IQR/main.js +7 -0
- package/src/IQR/types.d.ts +3 -0
- package/src/IQR/utils.d.ts +3 -0
- package/src/IQR/utils.js +18 -0
- package/src/MAD/main.d.ts +2 -2
- package/src/MAD/main.js +5 -16
- package/src/MAD/types.d.ts +3 -1
- package/src/MAD/utils.d.ts +2 -0
- package/src/MAD/utils.js +15 -0
- package/src/compare/main.d.ts +7 -4
- package/src/compare/main.js +12 -5
- package/src/compare/types.d.ts +13 -3
- package/src/compare/utils.d.ts +3 -1
- package/src/compare/utils.js +42 -22
- package/src/mathOperations/div/utils.js +2 -6
- package/src/mathOperations/mul/utils.js +2 -1
- package/src/mean/main.js +6 -3
- package/src/mean/types.d.ts +2 -0
- package/src/mean/utils.d.ts +2 -0
- package/src/mean/utils.js +10 -0
- package/src/quartile/types.d.ts +1 -1
- package/src/quartile/utils.js +5 -5
- package/src/shared/constant.d.ts +12 -0
- package/src/shared/constant.js +12 -0
- package/src/shared/utils.js +1 -1
- package/src/sort/utils.js +4 -4
package/README.md
CHANGED
@@ -18,7 +18,13 @@
|
|
18
18
|
* **Flexible Rounding:** Round numbers to the nearest integer or a specific number of decimal places with various rounding modes (up, down, half-up, half-down, half-even, half-odd) to meet your exact requirements.
|
19
19
|
* **Round Based on Significant Figures:** Control rounding based on the number of significant figures, crucial for scientific and engineering applications.
|
20
20
|
* **Chain Operations with Pipe:** Simplify complex calculations by chaining arithmetic operations in a readable and intuitive manner.
|
21
|
-
* **Analyze Data Distribution:**
|
21
|
+
* **Analyze Data Distribution:**
|
22
|
+
* **Calculate Quartiles (Q1, Q2, Q3):** Understand the spread and central tendency of your numerical data, helping identify outliers and the shape of the distribution.
|
23
|
+
* **Calculate Median Absolute Deviation (MAD):** Measure the dispersion of a dataset, providing a robust alternative to standard deviation that is less sensitive to outliers.
|
24
|
+
* **Calculate Interquartile Range (IQR):** Determine the spread of the middle 50% of your data, useful for identifying the central bulk and potential outliers.
|
25
|
+
* **Compare Numbers:**
|
26
|
+
* **Check for Equality (`isEqual`):** Accurately determine if two arbitrary-precision numbers are equal.
|
27
|
+
* **Check if Left is Greater (`isLeftGreater`):** Precisely compare two arbitrary-precision numbers to see if the left operand is greater than the right.
|
22
28
|
* **Sort Numbers Accurately:** Sort arrays of numbers, including negative and decimal values, in ascending or descending order, correctly handling string representations of numbers that JavaScript's native sort might misinterpret.
|
23
29
|
* **Calculate Central Tendency:** Easily compute the mean (average) of a set of numbers.
|
24
30
|
* **Identify Extremes:** Find the maximum and minimum values within an array of numbers.
|
@@ -38,11 +44,9 @@ With `@numio/bigmath`, you can confidently perform complex arithmetic operations
|
|
38
44
|
|
39
45
|
### Latest update
|
40
46
|
|
41
|
-
Added
|
42
|
-
|
43
|
-
Added
|
44
|
-
Understanding Distribution. Quartiles (Q1, Q2, and Q3) split a dataset into four groups, each representing 25% of the data.
|
45
|
-
Identifying Outliers. They help visualize the shape and spread of the data, revealing whether it's skewed or symmetrical.
|
47
|
+
Added `isEqual` and `isLeftGreater` - to compare 2 numbers.
|
48
|
+
Added `MAD` - Median Absolute Deviation.
|
49
|
+
Added `IQR` - Interquartile Range.
|
46
50
|
|
47
51
|
# Install:
|
48
52
|
|
@@ -83,7 +87,7 @@ deno add jsr:@numio/bigmath
|
|
83
87
|
```javascript
|
84
88
|
import { add } from "@numio/bigmath";
|
85
89
|
|
86
|
-
const int = add(["12345", "99"]); //
|
90
|
+
const int = add(["12345", "99"]); // 12444
|
87
91
|
const float = add(["0.1", "0.2", "0.3"]); // 0.6
|
88
92
|
const negative = add(["0.1", "-0.3", "0.1"]); // -0.1
|
89
93
|
```
|
@@ -252,6 +256,38 @@ import { min } from "@numio/bigmath";
|
|
252
256
|
min(["2", "-1", "0.1"]) // -1;
|
253
257
|
```
|
254
258
|
|
259
|
+
### IsEqual
|
260
|
+
```javascript
|
261
|
+
import { isEqual } from "@numio/bigmath";
|
262
|
+
|
263
|
+
isEqual({left: "0.1", right: "0.1"}) // true;
|
264
|
+
isEqual({left: "2", right: "0.1"}) // false;
|
265
|
+
```
|
266
|
+
|
267
|
+
### IsLeftGreater
|
268
|
+
```javascript
|
269
|
+
import { isLeftGreater } from "@numio/bigmath";
|
270
|
+
|
271
|
+
isLeftGreater({left: "0.1", right: "2"}) // false;
|
272
|
+
isLeftGreater({left: "2", right: "0.1"}) // true;
|
273
|
+
isLeftGreater({left: "0.1", right: "0.1"}) // false;
|
274
|
+
isLeftGreater({left: "0.1", right: "-0.1"}) // true;
|
275
|
+
```
|
276
|
+
|
277
|
+
### MAD - Median Absolute Deviation
|
278
|
+
```javascript
|
279
|
+
import { MAD } from "@numio/bigmath";
|
280
|
+
|
281
|
+
MAD(["7", "15", "36", "39", "40", "41"]) // 3;
|
282
|
+
```
|
283
|
+
|
284
|
+
### IQR - Interquartile Range
|
285
|
+
```javascript
|
286
|
+
import { IQR } from "@numio/bigmath";
|
287
|
+
|
288
|
+
IQR(["7", "15", "36", "39", "40", "41"]) // 25;
|
289
|
+
```
|
290
|
+
|
255
291
|
Does not have a limitation on the number of digits. You can use any length you'd
|
256
292
|
like
|
257
293
|
|
package/index.d.ts
CHANGED
@@ -7,5 +7,7 @@ import { pipe } from "./src/pipe/main.d.ts";
|
|
7
7
|
import { quartile } from "./src/quartile/main.d.ts";
|
8
8
|
import { sort } from "./src/sort/main.d.ts";
|
9
9
|
import { mean } from "./src/mean/main.d.ts";
|
10
|
-
import {
|
11
|
-
|
10
|
+
import { isEqual, isLeftGreater, max, min } from "./src/compare/main.d.ts";
|
11
|
+
import { IQR } from "./src/IQR/main.d.ts";
|
12
|
+
import { MAD } from "./src/MAD/main.d.ts";
|
13
|
+
export { add, div, IQR, isEqual, isLeftGreater, MAD, max, mean, min, mul, pipe, quartile, round, sort, sub, };
|
package/index.js
CHANGED
@@ -7,5 +7,7 @@ import { pipe } from "./src/pipe/main.js";
|
|
7
7
|
import { quartile } from "./src/quartile/main.js";
|
8
8
|
import { sort } from "./src/sort/main.js";
|
9
9
|
import { mean } from "./src/mean/main.js";
|
10
|
-
import {
|
11
|
-
|
10
|
+
import { isEqual, isLeftGreater, max, min } from "./src/compare/main.js";
|
11
|
+
import { IQR } from "./src/IQR/main.js";
|
12
|
+
import { MAD } from "./src/MAD/main.js";
|
13
|
+
export { add, div, IQR, isEqual, isLeftGreater, MAD, max, mean, min, mul, pipe, quartile, round, sort, sub, };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@numio/bigmath",
|
3
3
|
"description": "@numio/bigmath is an arbitrary-precision arithmetic library. It can be used for basic operations with decimal numbers (integers and float)",
|
4
|
-
"version": "1.0.
|
4
|
+
"version": "1.0.10",
|
5
5
|
"keywords": [
|
6
6
|
"precision",
|
7
7
|
"arithmetic",
|
@@ -38,7 +38,13 @@
|
|
38
38
|
"max",
|
39
39
|
"sort",
|
40
40
|
"mean",
|
41
|
-
"significant figures"
|
41
|
+
"significant figures",
|
42
|
+
"MAD",
|
43
|
+
"Median Absolute Deviation",
|
44
|
+
"IQR",
|
45
|
+
"Interquartile Range",
|
46
|
+
"isEqual",
|
47
|
+
"equality"
|
42
48
|
],
|
43
49
|
"repository": {
|
44
50
|
"type": "git",
|
package/src/IQR/main.js
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
import { a2s, s2a } from "../shared/utils.js";
|
2
|
+
import { IQRInner } from "./utils.js";
|
3
|
+
//** This function returns Interquartile Range */
|
4
|
+
export var IQR = function (strs, sigNum) {
|
5
|
+
var array = strs.map(function (str) { return s2a(str); });
|
6
|
+
return a2s(IQRInner(array, sigNum));
|
7
|
+
};
|
package/src/IQR/utils.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
import { isEqualInner } from "../compare/utils.js";
|
2
|
+
import { MADInner } from "../MAD/utils.js";
|
3
|
+
import { subRoute } from "../mathOperations/sub/utils.js";
|
4
|
+
import { quartileInner } from "../quartile/utils.js";
|
5
|
+
import { DEFAULT, NIL, ONE } from "../shared/constant.js";
|
6
|
+
export var MIN_LENGTH_FOR_MAD = 30;
|
7
|
+
export var IQRInner = function (array, sigNum) {
|
8
|
+
if (sigNum === void 0) { sigNum = false; }
|
9
|
+
var _a = quartileInner(array), Q1 = _a.Q1, Q3 = _a.Q3;
|
10
|
+
var sub = subRoute([structuredClone(Q3), structuredClone(Q1)], DEFAULT);
|
11
|
+
if (sigNum) {
|
12
|
+
var isEqual = isEqualInner({ left: Q3, right: Q1 });
|
13
|
+
var MAD = MADInner(array);
|
14
|
+
var nonNilMAD = isEqualInner({ left: MAD, right: NIL }) ? ONE : MAD;
|
15
|
+
return isEqual ? nonNilMAD : sub;
|
16
|
+
}
|
17
|
+
return sub;
|
18
|
+
};
|
package/src/MAD/main.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import type {
|
2
|
-
export declare const
|
1
|
+
import type { TMAD } from "./types.d.ts";
|
2
|
+
export declare const MAD: TMAD;
|
package/src/MAD/main.js
CHANGED
@@ -1,18 +1,7 @@
|
|
1
|
-
import { subRoute } from "../mathOperations/sub/utils.js";
|
2
|
-
import { mean } from "../mean/main.js";
|
3
|
-
import { quartileInner } from "../quartile/utils.js";
|
4
|
-
import { DEFAULT } from "../shared/constant.js";
|
5
1
|
import { a2s, s2a } from "../shared/utils.js";
|
6
|
-
import {
|
7
|
-
|
8
|
-
export var
|
9
|
-
var
|
10
|
-
|
11
|
-
.map(function (element) {
|
12
|
-
var res = subRoute([s2a(element), s2a(meanOfAnArray)], DEFAULT);
|
13
|
-
res.isNegative = false;
|
14
|
-
return res;
|
15
|
-
});
|
16
|
-
var sorted = sortInner(madArray, ASC);
|
17
|
-
return a2s(quartileInner(sorted).Q2);
|
2
|
+
import { MADInner } from "./utils.js";
|
3
|
+
//** This function returns Median Absolute Deviation */
|
4
|
+
export var MAD = function (strs) {
|
5
|
+
var array = strs.map(function (str) { return s2a(str); });
|
6
|
+
return a2s(MADInner(array));
|
18
7
|
};
|
package/src/MAD/types.d.ts
CHANGED
package/src/MAD/utils.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import { subRoute } from "../mathOperations/sub/utils.js";
|
2
|
+
import { quartileInner } from "../quartile/utils.js";
|
3
|
+
import { DEFAULT } from "../shared/constant.js";
|
4
|
+
import { ASC } from "../sort/constants.js";
|
5
|
+
import { sortInner } from "../sort/utils.js";
|
6
|
+
export var MADInner = function (array) {
|
7
|
+
var median = quartileInner(array).Q2;
|
8
|
+
var madArray = array.map(function (el) {
|
9
|
+
var res = subRoute([structuredClone(el), structuredClone(median)], DEFAULT);
|
10
|
+
res.isNegative = false;
|
11
|
+
return res;
|
12
|
+
});
|
13
|
+
var sorted = sortInner(madArray, ASC);
|
14
|
+
return quartileInner(sorted).Q2;
|
15
|
+
};
|
package/src/compare/main.d.ts
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
import type { Max, Min } from "./types.d.ts";
|
2
|
-
/** This function returns max
|
1
|
+
import type { IsEqual, IsLeftGreater, Max, Min } from "./types.d.ts";
|
2
|
+
/** This function returns max value. */
|
3
3
|
export declare const max: Max;
|
4
|
-
/** This function returns min
|
4
|
+
/** This function returns min value. */
|
5
5
|
export declare const min: Min;
|
6
|
-
|
6
|
+
/** This function returns if left value is greater than right value */
|
7
|
+
export declare const isLeftGreater: IsLeftGreater;
|
8
|
+
/** This function returns if left and right values are equal */
|
9
|
+
export declare const isEqual: IsEqual;
|
package/src/compare/main.js
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
import { a2s, s2a } from "../shared/utils.js";
|
2
|
-
import {
|
3
|
-
/** This function returns max
|
2
|
+
import { isEqualInner, isLeftGreaterInner, maxInner, minInner } from "./utils.js";
|
3
|
+
/** This function returns max value. */
|
4
4
|
export var max = function (strs) {
|
5
5
|
var array = strs.map(function (str) { return s2a(str); });
|
6
6
|
return a2s(maxInner(array));
|
7
7
|
};
|
8
|
-
/** This function returns min
|
8
|
+
/** This function returns min value. */
|
9
9
|
export var min = function (strs) {
|
10
10
|
var array = strs.map(function (str) { return s2a(str); });
|
11
11
|
return a2s(minInner(array));
|
12
12
|
};
|
13
|
-
|
14
|
-
|
13
|
+
/** This function returns if left value is greater than right value */
|
14
|
+
export var isLeftGreater = function (_a) {
|
15
|
+
var left = _a.left, right = _a.right;
|
16
|
+
return isLeftGreaterInner({ left: s2a(left), right: s2a(right) });
|
17
|
+
};
|
18
|
+
/** This function returns if left and right values are equal */
|
19
|
+
export var isEqual = function (_a) {
|
20
|
+
var left = _a.left, right = _a.right;
|
21
|
+
return isEqualInner({ left: s2a(left), right: s2a(right) });
|
15
22
|
};
|
package/src/compare/types.d.ts
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
import type { InputData } from "../types.d.ts";
|
2
|
-
export type CompareInner = (left: InputData, right: InputData) => [InputData, boolean];
|
3
2
|
export type Min = (strs: string[]) => string;
|
4
|
-
export type Max =
|
3
|
+
export type Max = Min;
|
4
|
+
export type IsLeftGreater = (attr: {
|
5
|
+
left: string;
|
6
|
+
right: string;
|
7
|
+
}) => boolean;
|
8
|
+
export type IsEqual = IsLeftGreater;
|
9
|
+
export type CompareInner = (left: InputData, right: InputData) => [InputData, number];
|
5
10
|
export type MinInner = (array: InputData[]) => InputData;
|
6
|
-
export type MaxInner =
|
11
|
+
export type MaxInner = MinInner;
|
12
|
+
export type IsEqualInner = (attr: {
|
13
|
+
left: InputData;
|
14
|
+
right: InputData;
|
15
|
+
}) => boolean;
|
16
|
+
export type IsLeftGreaterInner = IsEqualInner;
|
package/src/compare/utils.d.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
import type { CompareInner, MaxInner, MinInner } from "./types.d.ts";
|
1
|
+
import type { CompareInner, IsEqualInner, IsLeftGreaterInner, MaxInner, MinInner } from "./types.d.ts";
|
2
2
|
export declare const maxInner: MaxInner;
|
3
3
|
export declare const minInner: MinInner;
|
4
4
|
export declare const compareInner: CompareInner;
|
5
|
+
export declare const isEqualInner: IsEqualInner;
|
6
|
+
export declare const isLeftGreaterInner: IsLeftGreaterInner;
|
package/src/compare/utils.js
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
export var maxInner = function (array) {
|
2
2
|
var max = array[0];
|
3
3
|
for (var i = 1; i < array.length; i++) {
|
4
|
-
compareInner(
|
4
|
+
if (compareInner(array[i], max)[1] === 1)
|
5
|
+
max = array[i];
|
5
6
|
}
|
6
7
|
return max;
|
7
8
|
};
|
8
9
|
export var minInner = function (array) {
|
9
10
|
var min = array[0];
|
10
11
|
for (var i = 1; i < array.length; i++) {
|
11
|
-
compareInner(
|
12
|
+
if (compareInner(array[i], min)[1] === -1)
|
13
|
+
min = array[i];
|
12
14
|
}
|
13
15
|
return min;
|
14
16
|
};
|
@@ -24,51 +26,69 @@ export var compareInner = function (l, r) {
|
|
24
26
|
var bothPos = !lIsNeg && !rIsNeg;
|
25
27
|
var bothIntPos = lIntLen > 0 && rIntLen > 0;
|
26
28
|
var bothIntNeg = lIntLen <= 0 && rIntLen <= 0;
|
29
|
+
var isNilL = l.array.length === 1 && l.array[0] === 48;
|
30
|
+
var isNilR = r.array.length === 1 && r.array[0] === 48;
|
27
31
|
if (lIsNeg && !rIsNeg)
|
28
|
-
return [r,
|
32
|
+
return [r, -1];
|
29
33
|
if (!lIsNeg && rIsNeg)
|
30
|
-
return [l,
|
34
|
+
return [l, 1];
|
35
|
+
if (bothPos && isNilL && !isNilR)
|
36
|
+
return [r, -1];
|
37
|
+
if (bothPos && !isNilL && isNilR)
|
38
|
+
return [l, 1];
|
39
|
+
if (bothNeg && isNilL && !isNilR)
|
40
|
+
return [l, 1];
|
41
|
+
if (bothNeg && !isNilL && isNilR)
|
42
|
+
return [r, -1];
|
31
43
|
if (bothPos && lIntLen > 0 && rIntLen === 0)
|
32
|
-
return [l,
|
44
|
+
return [l, 1];
|
33
45
|
if (bothPos && lIntLen === 0 && rIntLen > 0)
|
34
|
-
return [r,
|
46
|
+
return [r, -1];
|
35
47
|
if (!bothPos && lIntLen > 0 && rIntLen === 0)
|
36
|
-
return [r,
|
48
|
+
return [r, -1];
|
37
49
|
if (!bothPos && lIntLen === 0 && rIntLen > 0)
|
38
|
-
return [l,
|
50
|
+
return [l, 1];
|
39
51
|
if (bothPos && bothIntPos && lIntLen < rIntLen)
|
40
|
-
return [r,
|
52
|
+
return [r, -1];
|
41
53
|
if (bothPos && bothIntNeg && lIntLen < rIntLen)
|
42
|
-
return [r,
|
54
|
+
return [r, -1];
|
43
55
|
if (bothNeg && bothIntPos && lIntLen < rIntLen)
|
44
|
-
return [l,
|
56
|
+
return [l, 1];
|
45
57
|
if (bothNeg && bothIntNeg && lIntLen < rIntLen)
|
46
|
-
return [l,
|
58
|
+
return [l, 1];
|
47
59
|
if (bothNeg && bothIntNeg && lIntLen > rIntLen)
|
48
|
-
return [r,
|
60
|
+
return [r, -1];
|
49
61
|
if (bothNeg && bothIntPos && lIntLen > rIntLen)
|
50
|
-
return [r,
|
62
|
+
return [r, -1];
|
51
63
|
if (bothPos && bothIntPos && lIntLen > rIntLen)
|
52
|
-
return [l,
|
64
|
+
return [l, 1];
|
53
65
|
if (bothPos && bothIntNeg && lIntLen > rIntLen)
|
54
|
-
return [l,
|
66
|
+
return [l, 1];
|
55
67
|
if (bothNeg)
|
56
68
|
_a = [r, l], left = _a[0], right = _a[1];
|
57
69
|
while (idx < (lenL > lenR ? lenL : lenR)) {
|
58
70
|
var numL = left.array[idx];
|
59
71
|
var numR = right.array[idx];
|
60
72
|
if (!numL && bothPos)
|
61
|
-
return [r,
|
73
|
+
return [r, -1];
|
62
74
|
if (!numR && bothPos)
|
63
|
-
return [l,
|
75
|
+
return [l, 1];
|
64
76
|
if (!numL && bothNeg)
|
65
|
-
return [l,
|
77
|
+
return [l, 1];
|
66
78
|
if (!numR && bothNeg)
|
67
|
-
return [r,
|
79
|
+
return [r, -1];
|
68
80
|
if (numL !== numR) {
|
69
|
-
return numL > numR ? [l,
|
81
|
+
return numL > numR ? [l, 1] : [r, -1];
|
70
82
|
}
|
71
83
|
idx += 1;
|
72
84
|
}
|
73
|
-
return [l,
|
85
|
+
return [l, 0];
|
86
|
+
};
|
87
|
+
export var isEqualInner = function (_a) {
|
88
|
+
var left = _a.left, right = _a.right;
|
89
|
+
return compareInner(left, right)[1] === 0;
|
90
|
+
};
|
91
|
+
export var isLeftGreaterInner = function (_a) {
|
92
|
+
var left = _a.left, right = _a.right;
|
93
|
+
return compareInner(left, right)[1] > 0;
|
74
94
|
};
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { NIL } from "../../shared/constant.js";
|
1
2
|
export var divInner = function (_a, _b, isNegative, initLimit) {
|
2
3
|
var arrL = _a[0], intL = _a[1];
|
3
4
|
var arrR = _b[0], intR = _b[1];
|
@@ -81,12 +82,7 @@ export var divInner = function (_a, _b, isNegative, initLimit) {
|
|
81
82
|
}
|
82
83
|
}
|
83
84
|
return result.length === count
|
84
|
-
?
|
85
|
-
array: [48],
|
86
|
-
isFloat: false,
|
87
|
-
isNegative: false,
|
88
|
-
intLength: 1,
|
89
|
-
}
|
85
|
+
? NIL
|
90
86
|
: {
|
91
87
|
array: result[0] === 48 ? multipliedResult : result,
|
92
88
|
isFloat: isFloat,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { NIL } from "../../shared/constant.js";
|
1
2
|
/** This function multiplies 2 numbers (as array). */
|
2
3
|
export var mulInner = function (_a, _b, isNegative) {
|
3
4
|
var _c, _d;
|
@@ -6,7 +7,7 @@ export var mulInner = function (_a, _b, isNegative) {
|
|
6
7
|
if (arrL.length === 0 || arrR.length === 0 ||
|
7
8
|
(arrL.length === 1 && arrL[0] === 48) ||
|
8
9
|
(arrR.length === 1 && arrR[0] === 48)) {
|
9
|
-
return
|
10
|
+
return NIL;
|
10
11
|
}
|
11
12
|
var dec = (arrL.length - intL) + (arrR.length - intR);
|
12
13
|
var _e = arrL.length >= arrR.length
|
package/src/mean/main.js
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { a2s, s2a } from "../shared/utils.js";
|
2
|
+
import { meanInner } from "./utils.js";
|
2
3
|
/** This function returns mean of an array. */
|
3
|
-
export var mean = function (
|
4
|
-
|
4
|
+
export var mean = function (strs) {
|
5
|
+
var array = strs.map(function (str) { return s2a(str); });
|
6
|
+
var res = meanInner(array);
|
7
|
+
return a2s(res);
|
5
8
|
};
|
package/src/mean/types.d.ts
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
import { addRoute } from "../mathOperations/add/utils.js";
|
2
|
+
import { divInner } from "../mathOperations/div/utils.js";
|
3
|
+
import { DEFAULT } from "../shared/constant.js";
|
4
|
+
import { s2a } from "../shared/utils.js";
|
5
|
+
export var meanInner = function (array) {
|
6
|
+
var left = addRoute(array, DEFAULT);
|
7
|
+
var right = s2a(array.length.toString());
|
8
|
+
var res = divInner([left.array, left.intLength], [right.array, right.intLength], left.isNegative !== right.isNegative, 20);
|
9
|
+
return res;
|
10
|
+
};
|
package/src/quartile/types.d.ts
CHANGED
@@ -4,7 +4,7 @@ export type Quartile = (array: string[]) => {
|
|
4
4
|
Q2: string;
|
5
5
|
Q3: string;
|
6
6
|
};
|
7
|
-
export type
|
7
|
+
export type MeanQ = (index: number, array: InputData[]) => InputData;
|
8
8
|
export type QuartileInner = (array: InputData[]) => {
|
9
9
|
Q1: InputData;
|
10
10
|
Q2: InputData;
|
package/src/quartile/utils.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { addRoute } from "../mathOperations/add/utils.js";
|
2
2
|
import { divRoute } from "../mathOperations/div/utils.js";
|
3
3
|
import { DEFAULT } from "../shared/constant.js";
|
4
|
-
var
|
5
|
-
var sum = addRoute([structuredClone(array[idx]), array[idx - 1]], DEFAULT);
|
4
|
+
var meanQ = function (idx, array) {
|
5
|
+
var sum = addRoute([structuredClone(array[idx]), structuredClone(array[idx - 1])], DEFAULT);
|
6
6
|
return divRoute([sum, {
|
7
7
|
array: [50],
|
8
8
|
intLength: 1,
|
@@ -20,8 +20,8 @@ export var quartileInner = function (array) {
|
|
20
20
|
var Q3Idx = length - Q1Idx;
|
21
21
|
var isEvenHalf = Q2Idx % 2 !== 0;
|
22
22
|
return {
|
23
|
-
Q1: isEvenHalf ? array[Q1Idx] :
|
24
|
-
Q2: length % 2 !== 0 ? array[Q2Idx] :
|
25
|
-
Q3: isEvenHalf ? array[Q3Idx - 1] :
|
23
|
+
Q1: isEvenHalf ? array[Q1Idx] : meanQ(Q1Idx, array),
|
24
|
+
Q2: length % 2 !== 0 ? array[Q2Idx] : meanQ(Q2Idx, array),
|
25
|
+
Q3: isEvenHalf ? array[Q3Idx - 1] : meanQ(Q3Idx, array),
|
26
26
|
};
|
27
27
|
};
|
package/src/shared/constant.d.ts
CHANGED
@@ -4,3 +4,15 @@ export declare const DEFAULT: {
|
|
4
4
|
isFloat: boolean;
|
5
5
|
isNegative: boolean;
|
6
6
|
};
|
7
|
+
export declare const NIL: {
|
8
|
+
array: number[];
|
9
|
+
isFloat: boolean;
|
10
|
+
isNegative: boolean;
|
11
|
+
intLength: number;
|
12
|
+
};
|
13
|
+
export declare const ONE: {
|
14
|
+
array: number[];
|
15
|
+
isFloat: boolean;
|
16
|
+
isNegative: boolean;
|
17
|
+
intLength: number;
|
18
|
+
};
|
package/src/shared/constant.js
CHANGED
@@ -4,3 +4,15 @@ export var DEFAULT = {
|
|
4
4
|
isFloat: false,
|
5
5
|
isNegative: false,
|
6
6
|
};
|
7
|
+
export var NIL = {
|
8
|
+
array: [48],
|
9
|
+
isFloat: false,
|
10
|
+
isNegative: false,
|
11
|
+
intLength: 1,
|
12
|
+
};
|
13
|
+
export var ONE = {
|
14
|
+
array: [49],
|
15
|
+
isFloat: false,
|
16
|
+
isNegative: false,
|
17
|
+
intLength: 1,
|
18
|
+
};
|
package/src/shared/utils.js
CHANGED
package/src/sort/utils.js
CHANGED
@@ -6,15 +6,15 @@ var heapify = function (array, len, i, sorting) {
|
|
6
6
|
var idxR = idxL + 1;
|
7
7
|
var idx = i;
|
8
8
|
if (sorting === ASC) {
|
9
|
-
if (idxL < len && compareInner(array[idxL], array[idx])[1])
|
9
|
+
if (idxL < len && compareInner(array[idxL], array[idx])[1] >= 0)
|
10
10
|
idx = idxL;
|
11
|
-
if (idxR < len && compareInner(array[idxR], array[idx])[1])
|
11
|
+
if (idxR < len && compareInner(array[idxR], array[idx])[1] >= 0)
|
12
12
|
idx = idxR;
|
13
13
|
}
|
14
14
|
else {
|
15
|
-
if (idxL < len && compareInner(array[idx], array[idxL])[1])
|
15
|
+
if (idxL < len && compareInner(array[idx], array[idxL])[1] >= 0)
|
16
16
|
idx = idxL;
|
17
|
-
if (idxR < len && compareInner(array[idx], array[idxR])[1])
|
17
|
+
if (idxR < len && compareInner(array[idx], array[idxR])[1] >= 0)
|
18
18
|
idx = idxR;
|
19
19
|
}
|
20
20
|
if (idx !== i) {
|