-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
bin_functions.js
63 lines (56 loc) · 1.39 KB
/
bin_functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
var isNumeric = require('fast-isnumeric');
module.exports = {
count: function(n, i, size) {
size[n]++;
return 1;
},
sum: function(n, i, size, counterData) {
var v = counterData[i];
if(isNumeric(v)) {
v = Number(v);
size[n] += v;
return v;
}
return 0;
},
avg: function(n, i, size, counterData, counts) {
var v = counterData[i];
if(isNumeric(v)) {
v = Number(v);
size[n] += v;
counts[n]++;
}
return 0;
},
min: function(n, i, size, counterData) {
var v = counterData[i];
if(isNumeric(v)) {
v = Number(v);
if(!isNumeric(size[n])) {
size[n] = v;
return v;
} else if(size[n] > v) {
var delta = v - size[n];
size[n] = v;
return delta;
}
}
return 0;
},
max: function(n, i, size, counterData) {
var v = counterData[i];
if(isNumeric(v)) {
v = Number(v);
if(!isNumeric(size[n])) {
size[n] = v;
return v;
} else if(size[n] < v) {
var delta = v - size[n];
size[n] = v;
return delta;
}
}
return 0;
}
};