1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.sum = sum;
|
7 | exports.max = max;
|
8 | exports.min = min;
|
9 | exports.mean = mean;
|
10 | exports.mode = mode;
|
11 | exports.getColumn = getColumn;
|
12 | exports.getSatByColumn = getSatByColumn;
|
13 | exports.statMap = void 0;
|
14 |
|
15 | function max(x) {
|
16 | if (x.length === 0) {
|
17 | throw new Error('max requires at least one data point');
|
18 | }
|
19 |
|
20 | var value = x[0];
|
21 |
|
22 | for (var i = 1; i < x.length; i++) {
|
23 | if (x[i] > value) {
|
24 | value = x[i];
|
25 | }
|
26 | }
|
27 |
|
28 | return value * 1;
|
29 | }
|
30 |
|
31 | function min(x) {
|
32 | if (x.length === 0) {
|
33 | throw new Error('min requires at least one data point');
|
34 | }
|
35 |
|
36 | var value = x[0];
|
37 |
|
38 | for (var i = 1; i < x.length; i++) {
|
39 | if (x[i] < value) {
|
40 | value = x[i];
|
41 | }
|
42 | }
|
43 |
|
44 | return value * 1;
|
45 | }
|
46 |
|
47 | function sum(x) {
|
48 | if (x.length === 0) {
|
49 | return 0;
|
50 | }
|
51 |
|
52 | var sumNum = x[0] * 1;
|
53 |
|
54 | for (var i = 1; i < x.length; i++) {
|
55 | sumNum += x[i] * 1;
|
56 | }
|
57 |
|
58 | return sumNum;
|
59 | }
|
60 |
|
61 | function mean(x) {
|
62 | if (x.length === 0) {
|
63 | throw new Error('mean requires at least one data point');
|
64 | }
|
65 |
|
66 | return sum(x) / x.length;
|
67 | }
|
68 |
|
69 | function mode(x) {
|
70 | if (x.length === 0) {
|
71 | throw new Error('mean requires at least one data point');
|
72 | }
|
73 |
|
74 | if (x.length < 3) {
|
75 | return x[0];
|
76 | }
|
77 |
|
78 | x.sort();
|
79 | var last = x[0];
|
80 | var value = NaN;
|
81 | var maxSeen = 0;
|
82 | var seenThis = 1;
|
83 |
|
84 | for (var i = 1; i < x.length + 1; i++) {
|
85 | if (x[i] !== last) {
|
86 | if (seenThis > maxSeen) {
|
87 | maxSeen = seenThis;
|
88 | value = last;
|
89 | }
|
90 |
|
91 | seenThis = 1;
|
92 | last = x[i];
|
93 | } else {
|
94 | seenThis++;
|
95 | }
|
96 | }
|
97 |
|
98 | return value * 1;
|
99 | }
|
100 |
|
101 | var statMap = {
|
102 | min: min,
|
103 | max: max,
|
104 | mean: mean,
|
105 | sum: sum,
|
106 | mode: mode
|
107 | };
|
108 | exports.statMap = statMap;
|
109 |
|
110 | function getColumn(data, columnName) {
|
111 | return data.map(function (item) {
|
112 | return item[columnName];
|
113 | });
|
114 | }
|
115 |
|
116 | function getSatByColumn(type, column) {
|
117 | return statMap[type](column);
|
118 | }
|
119 |
|
\ | No newline at end of file |