@numio/bigmath 1.0.7 → 1.0.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.
- package/index.d.ts +5 -5
- package/index.js +5 -5
- package/package.json +1 -1
- package/src/MAD/main.d.ts +2 -0
- package/src/MAD/main.js +18 -0
- package/src/MAD/types.d.ts +1 -0
- package/src/compare/main.d.ts +1 -4
- package/src/compare/main.js +4 -69
- package/src/compare/types.d.ts +3 -3
- package/src/compare/utils.d.ts +4 -0
- package/src/compare/utils.js +74 -0
- package/src/mathOperations/add/types.d.ts +1 -1
- package/src/mathOperations/add/utils.d.ts +2 -2
- package/src/mathOperations/add/utils.js +5 -5
- package/src/mathOperations/div/types.d.ts +1 -1
- package/src/mathOperations/div/utils.d.ts +2 -2
- package/src/mathOperations/div/utils.js +2 -2
- package/src/mathOperations/mul/types.d.ts +1 -1
- package/src/mathOperations/mul/utils.d.ts +2 -2
- package/src/mathOperations/mul/utils.js +2 -2
- package/src/mathOperations/sub/types.d.ts +1 -1
- package/src/mathOperations/sub/utils.d.ts +2 -2
- package/src/mathOperations/sub/utils.js +5 -5
- package/src/pipe/main.d.ts +2 -3
- package/src/pipe/main.js +4 -3
- package/src/quartile/main.js +8 -16
- package/src/quartile/types.d.ts +7 -1
- package/src/quartile/utils.d.ts +2 -0
- package/src/quartile/utils.js +27 -0
- package/src/shared/types.d.ts +1 -0
- package/src/shared/utils.js +6 -3
- package/src/sort/main.js +2 -36
- package/src/sort/types.d.ts +1 -1
- package/src/sort/utils.d.ts +2 -0
- package/src/sort/utils.js +36 -0
- /package/src/mathOperations/add/{index.d.ts → main.d.ts} +0 -0
- /package/src/mathOperations/add/{index.js → main.js} +0 -0
- /package/src/mathOperations/div/{index.d.ts → main.d.ts} +0 -0
- /package/src/mathOperations/div/{index.js → main.js} +0 -0
- /package/src/mathOperations/mul/{index.d.ts → main.d.ts} +0 -0
- /package/src/mathOperations/mul/{index.js → main.js} +0 -0
- /package/src/mathOperations/sub/{index.d.ts → main.d.ts} +0 -0
- /package/src/mathOperations/sub/{index.js → main.js} +0 -0
- /package/src/round/{index.d.ts → main.d.ts} +0 -0
- /package/src/round/{index.js → main.js} +0 -0
package/index.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { add } from "./src/mathOperations/add/
|
2
|
-
import { mul } from "./src/mathOperations/mul/
|
3
|
-
import { sub } from "./src/mathOperations/sub/
|
4
|
-
import { div } from "./src/mathOperations/div/
|
5
|
-
import { round } from "./src/round/
|
1
|
+
import { add } from "./src/mathOperations/add/main.d.ts";
|
2
|
+
import { mul } from "./src/mathOperations/mul/main.d.ts";
|
3
|
+
import { sub } from "./src/mathOperations/sub/main.d.ts";
|
4
|
+
import { div } from "./src/mathOperations/div/main.d.ts";
|
5
|
+
import { round } from "./src/round/main.d.ts";
|
6
6
|
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";
|
package/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { add } from "./src/mathOperations/add/
|
2
|
-
import { mul } from "./src/mathOperations/mul/
|
3
|
-
import { sub } from "./src/mathOperations/sub/
|
4
|
-
import { div } from "./src/mathOperations/div/
|
5
|
-
import { round } from "./src/round/
|
1
|
+
import { add } from "./src/mathOperations/add/main.js";
|
2
|
+
import { mul } from "./src/mathOperations/mul/main.js";
|
3
|
+
import { sub } from "./src/mathOperations/sub/main.js";
|
4
|
+
import { div } from "./src/mathOperations/div/main.js";
|
5
|
+
import { round } from "./src/round/main.js";
|
6
6
|
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";
|
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.8",
|
5
5
|
"keywords": [
|
6
6
|
"precision",
|
7
7
|
"arithmetic",
|
package/src/MAD/main.js
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
+
import { a2s, s2a } from "../shared/utils.js";
|
6
|
+
import { ASC } from "../sort/constants.js";
|
7
|
+
import { sortInner } from "../sort/utils.js";
|
8
|
+
export var MADQ2 = function (array) {
|
9
|
+
var meanOfAnArray = mean(array);
|
10
|
+
var madArray = array
|
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);
|
18
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export type TMADQ2 = (array: string[]) => string;
|
package/src/compare/main.d.ts
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
import type {
|
2
|
-
export declare const compareRawFn: CompareRawFn;
|
3
|
-
export declare const maxRawFn: MaxRawFn;
|
4
|
-
export declare const minRawFn: MinRawFn;
|
1
|
+
import type { Max, Min } from "./types.d.ts";
|
5
2
|
/** This function returns max number. */
|
6
3
|
export declare const max: Max;
|
7
4
|
/** This function returns min number. */
|
package/src/compare/main.js
CHANGED
@@ -1,80 +1,15 @@
|
|
1
1
|
import { a2s, s2a } from "../shared/utils.js";
|
2
|
-
|
3
|
-
var _a;
|
4
|
-
var idx = 0;
|
5
|
-
var _b = [l, r], left = _b[0], right = _b[1];
|
6
|
-
var lIsNeg = l.isNegative, lIntLen = l.intLength;
|
7
|
-
var rIsNeg = r.isNegative, rIntLen = r.intLength;
|
8
|
-
var lenL = l.array.length;
|
9
|
-
var lenR = r.array.length;
|
10
|
-
var bothNeg = lIsNeg && rIsNeg;
|
11
|
-
var bothPos = !lIsNeg && !rIsNeg;
|
12
|
-
var bothIntPos = lIntLen > 0 && rIntLen > 0;
|
13
|
-
var bothIntNeg = lIntLen <= 0 && rIntLen <= 0;
|
14
|
-
if (lIsNeg && !rIsNeg)
|
15
|
-
return [r, false];
|
16
|
-
if (!lIsNeg && rIsNeg)
|
17
|
-
return [l, true];
|
18
|
-
if (bothPos && bothIntPos && lIntLen < rIntLen)
|
19
|
-
return [r, false];
|
20
|
-
if (bothPos && bothIntNeg && lIntLen < rIntLen)
|
21
|
-
return [r, false];
|
22
|
-
if (bothNeg && bothIntPos && lIntLen < rIntLen)
|
23
|
-
return [l, true];
|
24
|
-
if (bothNeg && bothIntNeg && lIntLen < rIntLen)
|
25
|
-
return [l, true];
|
26
|
-
if (bothNeg && bothIntNeg && lIntLen > rIntLen)
|
27
|
-
return [r, false];
|
28
|
-
if (bothNeg && bothIntPos && lIntLen > rIntLen)
|
29
|
-
return [r, false];
|
30
|
-
if (bothPos && bothIntPos && lIntLen > rIntLen)
|
31
|
-
return [l, true];
|
32
|
-
if (bothPos && bothIntNeg && lIntLen > rIntLen)
|
33
|
-
return [l, true];
|
34
|
-
if (bothNeg)
|
35
|
-
_a = [r, l], left = _a[0], right = _a[1];
|
36
|
-
while (idx < (lenL > lenR ? lenL : lenR)) {
|
37
|
-
var numL = left.array[idx];
|
38
|
-
var numR = right.array[idx];
|
39
|
-
if (!numL && bothPos)
|
40
|
-
return [r, false];
|
41
|
-
if (!numR && bothPos)
|
42
|
-
return [l, true];
|
43
|
-
if (!numL && bothNeg)
|
44
|
-
return [l, true];
|
45
|
-
if (!numR && bothNeg)
|
46
|
-
return [r, false];
|
47
|
-
if (numL !== numR) {
|
48
|
-
return numL > numR ? [l, true] : [r, false];
|
49
|
-
}
|
50
|
-
idx += 1;
|
51
|
-
}
|
52
|
-
return [l, true];
|
53
|
-
};
|
54
|
-
export var maxRawFn = function (array) {
|
55
|
-
var max = array[0];
|
56
|
-
for (var i = 1; i < array.length; i++) {
|
57
|
-
compareRawFn(max, array[i])[1] || (max = array[i]);
|
58
|
-
}
|
59
|
-
return max;
|
60
|
-
};
|
61
|
-
export var minRawFn = function (array) {
|
62
|
-
var min = array[0];
|
63
|
-
for (var i = 1; i < array.length; i++) {
|
64
|
-
compareRawFn(min, array[i])[1] && (min = array[i]);
|
65
|
-
}
|
66
|
-
return min;
|
67
|
-
};
|
2
|
+
import { compareInner, maxInner, minInner } from "./utils.js";
|
68
3
|
/** This function returns max number. */
|
69
4
|
export var max = function (strs) {
|
70
5
|
var array = strs.map(function (str) { return s2a(str); });
|
71
|
-
return a2s(
|
6
|
+
return a2s(maxInner(array));
|
72
7
|
};
|
73
8
|
/** This function returns min number. */
|
74
9
|
export var min = function (strs) {
|
75
10
|
var array = strs.map(function (str) { return s2a(str); });
|
76
|
-
return a2s(
|
11
|
+
return a2s(minInner(array));
|
77
12
|
};
|
78
13
|
export var isGreater = function (l, r) {
|
79
|
-
return
|
14
|
+
return compareInner(s2a(l), s2a(r))[1];
|
80
15
|
};
|
package/src/compare/types.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { InputData } from "../types.d.ts";
|
2
|
-
export type
|
2
|
+
export type CompareInner = (left: InputData, right: InputData) => [InputData, boolean];
|
3
3
|
export type Min = (strs: string[]) => string;
|
4
4
|
export type Max = (strs: string[]) => string;
|
5
|
-
export type
|
6
|
-
export type
|
5
|
+
export type MinInner = (array: InputData[]) => InputData;
|
6
|
+
export type MaxInner = (array: InputData[]) => InputData;
|
@@ -0,0 +1,74 @@
|
|
1
|
+
export var maxInner = function (array) {
|
2
|
+
var max = array[0];
|
3
|
+
for (var i = 1; i < array.length; i++) {
|
4
|
+
compareInner(max, array[i])[1] || (max = array[i]);
|
5
|
+
}
|
6
|
+
return max;
|
7
|
+
};
|
8
|
+
export var minInner = function (array) {
|
9
|
+
var min = array[0];
|
10
|
+
for (var i = 1; i < array.length; i++) {
|
11
|
+
compareInner(min, array[i])[1] && (min = array[i]);
|
12
|
+
}
|
13
|
+
return min;
|
14
|
+
};
|
15
|
+
export var compareInner = function (l, r) {
|
16
|
+
var _a;
|
17
|
+
var idx = 0;
|
18
|
+
var _b = [l, r], left = _b[0], right = _b[1];
|
19
|
+
var lIsNeg = l.isNegative, lIntLen = l.intLength;
|
20
|
+
var rIsNeg = r.isNegative, rIntLen = r.intLength;
|
21
|
+
var lenL = l.array.length;
|
22
|
+
var lenR = r.array.length;
|
23
|
+
var bothNeg = lIsNeg && rIsNeg;
|
24
|
+
var bothPos = !lIsNeg && !rIsNeg;
|
25
|
+
var bothIntPos = lIntLen > 0 && rIntLen > 0;
|
26
|
+
var bothIntNeg = lIntLen <= 0 && rIntLen <= 0;
|
27
|
+
if (lIsNeg && !rIsNeg)
|
28
|
+
return [r, false];
|
29
|
+
if (!lIsNeg && rIsNeg)
|
30
|
+
return [l, true];
|
31
|
+
if (bothPos && lIntLen > 0 && rIntLen === 0)
|
32
|
+
return [l, true];
|
33
|
+
if (bothPos && lIntLen === 0 && rIntLen > 0)
|
34
|
+
return [r, false];
|
35
|
+
if (!bothPos && lIntLen > 0 && rIntLen === 0)
|
36
|
+
return [r, false];
|
37
|
+
if (!bothPos && lIntLen === 0 && rIntLen > 0)
|
38
|
+
return [l, true];
|
39
|
+
if (bothPos && bothIntPos && lIntLen < rIntLen)
|
40
|
+
return [r, false];
|
41
|
+
if (bothPos && bothIntNeg && lIntLen < rIntLen)
|
42
|
+
return [r, false];
|
43
|
+
if (bothNeg && bothIntPos && lIntLen < rIntLen)
|
44
|
+
return [l, true];
|
45
|
+
if (bothNeg && bothIntNeg && lIntLen < rIntLen)
|
46
|
+
return [l, true];
|
47
|
+
if (bothNeg && bothIntNeg && lIntLen > rIntLen)
|
48
|
+
return [r, false];
|
49
|
+
if (bothNeg && bothIntPos && lIntLen > rIntLen)
|
50
|
+
return [r, false];
|
51
|
+
if (bothPos && bothIntPos && lIntLen > rIntLen)
|
52
|
+
return [l, true];
|
53
|
+
if (bothPos && bothIntNeg && lIntLen > rIntLen)
|
54
|
+
return [l, true];
|
55
|
+
if (bothNeg)
|
56
|
+
_a = [r, l], left = _a[0], right = _a[1];
|
57
|
+
while (idx < (lenL > lenR ? lenL : lenR)) {
|
58
|
+
var numL = left.array[idx];
|
59
|
+
var numR = right.array[idx];
|
60
|
+
if (!numL && bothPos)
|
61
|
+
return [r, false];
|
62
|
+
if (!numR && bothPos)
|
63
|
+
return [l, true];
|
64
|
+
if (!numL && bothNeg)
|
65
|
+
return [l, true];
|
66
|
+
if (!numR && bothNeg)
|
67
|
+
return [r, false];
|
68
|
+
if (numL !== numR) {
|
69
|
+
return numL > numR ? [l, true] : [r, false];
|
70
|
+
}
|
71
|
+
idx += 1;
|
72
|
+
}
|
73
|
+
return [l, true];
|
74
|
+
};
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import type { InputData } from "../../types.d.ts";
|
2
|
-
export type
|
2
|
+
export type AddInner = (L: [number[], number], R: [number[], number], isNegative: boolean) => InputData;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Route } from "../../types.d.ts";
|
2
|
-
import type {
|
2
|
+
import type { AddInner } from "./types.d.ts";
|
3
3
|
/** This function adds 2 numbers (as array). */
|
4
|
-
export declare const
|
4
|
+
export declare const addInner: AddInner;
|
5
5
|
export declare const addRoute: Route;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { subInner } from "../sub/utils.js";
|
2
2
|
/** This function adds 2 numbers (as array). */
|
3
|
-
export var
|
3
|
+
export var addInner = function (_a, _b, isNegative) {
|
4
4
|
var _c, _d;
|
5
5
|
var arrL = _a[0], intL = _a[1];
|
6
6
|
var arrR = _b[0], intR = _b[1];
|
@@ -49,11 +49,11 @@ export var addRoute = function (input, initValue) {
|
|
49
49
|
if (left.array.length === 0)
|
50
50
|
return right;
|
51
51
|
if (left.isNegative && !right.isNegative) {
|
52
|
-
return
|
52
|
+
return subInner([right.array, right.intLength], [left.array, left.intLength]);
|
53
53
|
}
|
54
54
|
if (!left.isNegative && right.isNegative) {
|
55
|
-
return
|
55
|
+
return subInner([left.array, left.intLength], [right.array, right.intLength]);
|
56
56
|
}
|
57
|
-
return
|
57
|
+
return addInner([left.array, left.intLength], [right.array, right.intLength], left.isNegative && right.isNegative);
|
58
58
|
}, initValue);
|
59
59
|
};
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import type { InputData } from "../../types.d.ts";
|
2
|
-
export type
|
2
|
+
export type DivInner = (L: [number[], number], R: [number[], number], isNegative: boolean, initLimit: number) => InputData;
|
3
3
|
export type DivRoute = (input: InputData[], initValue: InputData, limit: number) => InputData;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import type {
|
2
|
-
export declare const
|
1
|
+
import type { DivInner, DivRoute } from "./types.d.ts";
|
2
|
+
export declare const divInner: DivInner;
|
3
3
|
export declare const divRoute: DivRoute;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export var
|
1
|
+
export var divInner = function (_a, _b, isNegative, initLimit) {
|
2
2
|
var arrL = _a[0], intL = _a[1];
|
3
3
|
var arrR = _b[0], intR = _b[1];
|
4
4
|
var decDiff = (arrL.length - intL) - (arrR.length - intR);
|
@@ -98,6 +98,6 @@ export var divRoute = function (input, initValue, limit) {
|
|
98
98
|
return input.reduce(function (left, right) {
|
99
99
|
if (left.array.length === 0)
|
100
100
|
return right;
|
101
|
-
return
|
101
|
+
return divInner([left.array, left.intLength], [right.array, right.intLength], left.isNegative !== right.isNegative, limit);
|
102
102
|
}, initValue);
|
103
103
|
};
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import type { InputData } from "../../types.d.ts";
|
2
|
-
export type
|
2
|
+
export type MulInner = (arrL: [number[], number], arrR: [number[], number], isNegative: boolean) => InputData;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Route } from "../../types.d.ts";
|
2
|
-
import type {
|
2
|
+
import type { MulInner } from "./types.d.ts";
|
3
3
|
/** This function multiplies 2 numbers (as array). */
|
4
|
-
export declare const
|
4
|
+
export declare const mulInner: MulInner;
|
5
5
|
export declare const mulRoute: Route;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/** This function multiplies 2 numbers (as array). */
|
2
|
-
export var
|
2
|
+
export var mulInner = function (_a, _b, isNegative) {
|
3
3
|
var _c, _d;
|
4
4
|
var arrL = _a[0], intL = _a[1];
|
5
5
|
var arrR = _b[0], intR = _b[1];
|
@@ -44,6 +44,6 @@ export var mulRoute = function (input, initValue) {
|
|
44
44
|
return input.reduce(function (left, right) {
|
45
45
|
if (left.array.length === 0)
|
46
46
|
return right;
|
47
|
-
return
|
47
|
+
return mulInner([left.array, left.intLength], [right.array, right.intLength], left.isNegative !== right.isNegative);
|
48
48
|
}, initValue);
|
49
49
|
};
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import type { InputData } from "../../types.d.ts";
|
2
|
-
export type
|
2
|
+
export type SubInner = (L: [number[], number], R: [number[], number]) => InputData;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Route } from "../../types.d.ts";
|
2
|
-
import type {
|
2
|
+
import type { SubInner } from "./types.d.ts";
|
3
3
|
/** This function subtracts 2 numbers (as array). */
|
4
|
-
export declare const
|
4
|
+
export declare const subInner: SubInner;
|
5
5
|
export declare const subRoute: Route;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { addInner } from "../add/utils.js";
|
2
2
|
/** This function subtracts 2 numbers (as array). */
|
3
|
-
export var
|
3
|
+
export var subInner = function (_a, _b) {
|
4
4
|
var _c, _d;
|
5
5
|
var _e, _f;
|
6
6
|
var arrL = _a[0], intL = _a[1];
|
@@ -71,11 +71,11 @@ export var subRoute = function (input, initValue) {
|
|
71
71
|
if (left.array.length === 0)
|
72
72
|
return right;
|
73
73
|
if (left.isNegative && right.isNegative) {
|
74
|
-
return
|
74
|
+
return subInner([right.array, right.intLength], [left.array, left.intLength]);
|
75
75
|
}
|
76
76
|
if (!left.isNegative && !right.isNegative) {
|
77
|
-
return
|
77
|
+
return subInner([left.array, left.intLength], [right.array, right.intLength]);
|
78
78
|
}
|
79
|
-
return
|
79
|
+
return addInner([left.array, left.intLength], [right.array, right.intLength], left.isNegative);
|
80
80
|
}, initValue);
|
81
81
|
};
|
package/src/pipe/main.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { A2S } from "../shared/types.d.ts";
|
2
2
|
import type { InputData } from "../types.d.ts";
|
3
|
-
declare class Pipe {
|
3
|
+
export declare class Pipe {
|
4
4
|
result: InputData;
|
5
|
-
constructor();
|
5
|
+
constructor(array: InputData);
|
6
6
|
add(strs: string[]): Pipe;
|
7
7
|
sub(strs: string[]): Pipe;
|
8
8
|
div(strs: string[], limit?: number): Pipe;
|
@@ -11,4 +11,3 @@ declare class Pipe {
|
|
11
11
|
}
|
12
12
|
/** Using this function you can chain operations (add, sub, div, mul). */
|
13
13
|
export declare const pipe: Pipe;
|
14
|
-
export {};
|
package/src/pipe/main.js
CHANGED
@@ -5,8 +5,8 @@ import { addRoute } from "../mathOperations/add/utils.js";
|
|
5
5
|
import { divRoute } from "../mathOperations/div/utils.js";
|
6
6
|
import { mulRoute } from "../mathOperations/mul/utils.js";
|
7
7
|
var Pipe = /** @class */ (function () {
|
8
|
-
function Pipe() {
|
9
|
-
this.result =
|
8
|
+
function Pipe(array) {
|
9
|
+
this.result = array;
|
10
10
|
}
|
11
11
|
Pipe.prototype.add = function (strs) {
|
12
12
|
this.result = addRoute(strs.map(function (str) { return s2a(str); }), this.result);
|
@@ -32,5 +32,6 @@ var Pipe = /** @class */ (function () {
|
|
32
32
|
};
|
33
33
|
return Pipe;
|
34
34
|
}());
|
35
|
+
export { Pipe };
|
35
36
|
/** Using this function you can chain operations (add, sub, div, mul). */
|
36
|
-
export var pipe = new Pipe();
|
37
|
+
export var pipe = new Pipe(DEFAULT);
|
package/src/quartile/main.js
CHANGED
@@ -1,20 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
return pipe.add([array[idx], array[idx - 1]]).div(["2"]).calc();
|
4
|
-
};
|
1
|
+
import { a2s, s2a } from "../shared/utils.js";
|
2
|
+
import { quartileInner } from "./utils.js";
|
5
3
|
/** This function returns Q1, Q2, Q3 (quartile). */
|
6
|
-
export var quartile = function (
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
var length = array.length;
|
11
|
-
var Q2Idx = length >> 1;
|
12
|
-
var Q1Idx = Q2Idx >> 1;
|
13
|
-
var Q3Idx = length - Q1Idx;
|
14
|
-
var isEvenHalf = Q2Idx % 2 !== 0;
|
4
|
+
export var quartile = function (strs) {
|
5
|
+
var array = strs.map(function (str) { return s2a(str); });
|
6
|
+
var Qs = quartileInner(array);
|
15
7
|
return {
|
16
|
-
Q1:
|
17
|
-
Q2:
|
18
|
-
Q3:
|
8
|
+
Q1: a2s(Qs.Q1),
|
9
|
+
Q2: a2s(Qs.Q2),
|
10
|
+
Q3: a2s(Qs.Q3),
|
19
11
|
};
|
20
12
|
};
|
package/src/quartile/types.d.ts
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
import type { InputData } from "../types.d.ts";
|
1
2
|
export type Quartile = (array: string[]) => {
|
2
3
|
Q1: string;
|
3
4
|
Q2: string;
|
4
5
|
Q3: string;
|
5
6
|
};
|
6
|
-
export type Mean = (index: number, array:
|
7
|
+
export type Mean = (index: number, array: InputData[]) => InputData;
|
8
|
+
export type QuartileInner = (array: InputData[]) => {
|
9
|
+
Q1: InputData;
|
10
|
+
Q2: InputData;
|
11
|
+
Q3: InputData;
|
12
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { addRoute } from "../mathOperations/add/utils.js";
|
2
|
+
import { divRoute } from "../mathOperations/div/utils.js";
|
3
|
+
import { DEFAULT } from "../shared/constant.js";
|
4
|
+
var mean = function (idx, array) {
|
5
|
+
var sum = addRoute([structuredClone(array[idx]), array[idx - 1]], DEFAULT);
|
6
|
+
return divRoute([sum, {
|
7
|
+
array: [50],
|
8
|
+
intLength: 1,
|
9
|
+
isFloat: false,
|
10
|
+
isNegative: false,
|
11
|
+
}], DEFAULT, 20);
|
12
|
+
};
|
13
|
+
export var quartileInner = function (array) {
|
14
|
+
if (array.length < 3) {
|
15
|
+
throw Error("To calculate quartile you need at least 3 elements");
|
16
|
+
}
|
17
|
+
var length = array.length;
|
18
|
+
var Q2Idx = length >> 1;
|
19
|
+
var Q1Idx = Q2Idx >> 1;
|
20
|
+
var Q3Idx = length - Q1Idx;
|
21
|
+
var isEvenHalf = Q2Idx % 2 !== 0;
|
22
|
+
return {
|
23
|
+
Q1: isEvenHalf ? array[Q1Idx] : mean(Q1Idx, array),
|
24
|
+
Q2: length % 2 !== 0 ? array[Q2Idx] : mean(Q2Idx, array),
|
25
|
+
Q3: isEvenHalf ? array[Q3Idx - 1] : mean(Q3Idx, array),
|
26
|
+
};
|
27
|
+
};
|
package/src/shared/types.d.ts
CHANGED
package/src/shared/utils.js
CHANGED
@@ -5,6 +5,9 @@ export var a2s = function (_a) {
|
|
5
5
|
var array = _a.array, isFloat = _a.isFloat, isNegative = _a.isNegative, intLength = _a.intLength;
|
6
6
|
var result = [];
|
7
7
|
var lastValuableIdx = array.length;
|
8
|
+
var isNil = array.length === 1 && array[0] === 48;
|
9
|
+
if (isNil)
|
10
|
+
return convert(isNegative, array);
|
8
11
|
if (isFloat) {
|
9
12
|
var idx = array.length - 1;
|
10
13
|
while (array[idx] === 48 && idx >= intLength) {
|
@@ -38,13 +41,13 @@ export var s2a = function (string) {
|
|
38
41
|
var shift = isNegative ? 1 : 0;
|
39
42
|
var dec = 0;
|
40
43
|
var isNil = string.length === 1 && string.charCodeAt(0) === 48;
|
41
|
-
var isNegNil = string.length === 2 &&
|
44
|
+
var isNegNil = string.length === 2 && isNegative &&
|
42
45
|
string.charCodeAt(1) === 48;
|
43
46
|
if (isNil || isNegNil) {
|
44
47
|
return {
|
45
48
|
array: [48],
|
46
|
-
intLength:
|
47
|
-
isNegative:
|
49
|
+
intLength: 0,
|
50
|
+
isNegative: isNegNil,
|
48
51
|
isFloat: false,
|
49
52
|
};
|
50
53
|
}
|
package/src/sort/main.js
CHANGED
@@ -1,44 +1,10 @@
|
|
1
|
-
import { compareRawFn } from "../compare/main.js";
|
2
1
|
import { a2s, s2a } from "../shared/utils.js";
|
3
2
|
import { ASC } from "./constants.js";
|
4
|
-
|
5
|
-
var _a;
|
6
|
-
var idxL = 2 * i + 1;
|
7
|
-
var idxR = idxL + 1;
|
8
|
-
var idx = i;
|
9
|
-
if (sorting === ASC) {
|
10
|
-
if (idxL < len && compareRawFn(array[idxL], array[idx])[1])
|
11
|
-
idx = idxL;
|
12
|
-
if (idxR < len && compareRawFn(array[idxR], array[idx])[1])
|
13
|
-
idx = idxR;
|
14
|
-
}
|
15
|
-
else {
|
16
|
-
if (idxL < len && compareRawFn(array[idx], array[idxL])[1])
|
17
|
-
idx = idxL;
|
18
|
-
if (idxR < len && compareRawFn(array[idx], array[idxR])[1])
|
19
|
-
idx = idxR;
|
20
|
-
}
|
21
|
-
if (idx !== i) {
|
22
|
-
_a = [array[idx], array[i]], array[i] = _a[0], array[idx] = _a[1];
|
23
|
-
heapify(array, len, idx, sorting);
|
24
|
-
}
|
25
|
-
};
|
26
|
-
var sortRawFn = function (array, sorting) {
|
27
|
-
var _a;
|
28
|
-
var len = array.length;
|
29
|
-
for (var i = (len >> 1) - 1; i >= 0; i--) {
|
30
|
-
heapify(array, len, i, sorting);
|
31
|
-
}
|
32
|
-
for (var i = len - 1; i >= 0; i--) {
|
33
|
-
_a = [array[i], array[0]], array[0] = _a[0], array[i] = _a[1];
|
34
|
-
heapify(array, i, 0, sorting);
|
35
|
-
}
|
36
|
-
return array;
|
37
|
-
};
|
3
|
+
import { sortInner } from "./utils.js";
|
38
4
|
/** Using this function sort an array. */
|
39
5
|
export var sort = function (array, sorting) {
|
40
6
|
if (sorting === void 0) { sorting = ASC; }
|
41
7
|
var inputDataArray = array.map(function (str) { return s2a(str); });
|
42
|
-
|
8
|
+
sortInner(inputDataArray, sorting);
|
43
9
|
return inputDataArray.map(function (input) { return a2s(input); });
|
44
10
|
};
|
package/src/sort/types.d.ts
CHANGED
@@ -2,5 +2,5 @@ import type { InputData } from "../types.d.ts";
|
|
2
2
|
import type { sortingArray } from "./constants.d.ts";
|
3
3
|
export type Sorting = typeof sortingArray[number];
|
4
4
|
export type Sort = (array: string[], sorting?: Sorting) => string[];
|
5
|
-
export type
|
5
|
+
export type SortInner = (array: InputData[], sorting: Sorting) => InputData[];
|
6
6
|
export type Heapify = (array: InputData[], len: number, i: number, sorting: Sorting) => void;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { compareInner } from "../compare/utils.js";
|
2
|
+
import { ASC } from "./constants.js";
|
3
|
+
var heapify = function (array, len, i, sorting) {
|
4
|
+
var _a;
|
5
|
+
var idxL = 2 * i + 1;
|
6
|
+
var idxR = idxL + 1;
|
7
|
+
var idx = i;
|
8
|
+
if (sorting === ASC) {
|
9
|
+
if (idxL < len && compareInner(array[idxL], array[idx])[1])
|
10
|
+
idx = idxL;
|
11
|
+
if (idxR < len && compareInner(array[idxR], array[idx])[1])
|
12
|
+
idx = idxR;
|
13
|
+
}
|
14
|
+
else {
|
15
|
+
if (idxL < len && compareInner(array[idx], array[idxL])[1])
|
16
|
+
idx = idxL;
|
17
|
+
if (idxR < len && compareInner(array[idx], array[idxR])[1])
|
18
|
+
idx = idxR;
|
19
|
+
}
|
20
|
+
if (idx !== i) {
|
21
|
+
_a = [array[idx], array[i]], array[i] = _a[0], array[idx] = _a[1];
|
22
|
+
heapify(array, len, idx, sorting);
|
23
|
+
}
|
24
|
+
};
|
25
|
+
export var sortInner = function (array, sorting) {
|
26
|
+
var _a;
|
27
|
+
var len = array.length;
|
28
|
+
for (var i = (len >> 1) - 1; i >= 0; i--) {
|
29
|
+
heapify(array, len, i, sorting);
|
30
|
+
}
|
31
|
+
for (var i = len - 1; i >= 0; i--) {
|
32
|
+
_a = [array[i], array[0]], array[0] = _a[0], array[i] = _a[1];
|
33
|
+
heapify(array, i, 0, sorting);
|
34
|
+
}
|
35
|
+
return array;
|
36
|
+
};
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|