1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.createQuartile = void 0;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function quantileSorted(arr, percentage) {
|
12 | const len = arr.length;
|
13 | if (!len) {
|
14 | return undefined;
|
15 | }
|
16 | if (len < 2) {
|
17 | return arr[len - 1];
|
18 | }
|
19 | const i = (len - 1) * percentage;
|
20 | const i0 = Math.floor(i);
|
21 | const v0 = arr[i0];
|
22 | const v1 = arr[i0 + 1];
|
23 | return v0 + (v1 - v0) * (i - i0);
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function createQuartile(arr, n, isSorted = false) {
|
34 | const numberArr = arr;
|
35 | if (!isSorted) {
|
36 | numberArr.sort((a, b) => a - b);
|
37 | }
|
38 | const tmp = [];
|
39 | for (let i = 1; i < n; i += 1) {
|
40 | tmp.push(quantileSorted(numberArr, i / n));
|
41 | }
|
42 | return tmp;
|
43 | }
|
44 | exports.createQuartile = createQuartile;
|
45 |
|
\ | No newline at end of file |