-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (54 loc) · 1.25 KB
/
index.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
module.exports = function Group () {
var stats
var n = []
var values = []
var name = ''
if (arguments.length > 1) {
// Convert Array-like arguments to real array
stats = Array.prototype.slice.call(arguments)
} else if (arguments.length === 1) {
// Only one argument provided - maybe array of objects?
if (Array.isArray(arguments[0])) {
stats = arguments[0]
} else {
stats = [arguments[0]]
}
} else {
throw new Error('No function arguments')
}
// Guess group name
stats.forEach(function (stat) {
if (name === '') {
name = stat.name
} else if (name !== stat.name) {
name = 'group'
}
})
var group = function group () {
// Check if arguments exist
if (arguments.length) {
// Values pushed to series object:
var args = arguments
// Iterate over all series functions
stats.forEach(function (stat, i) {
values[i] = stat(args[i])
n[i] = stat.n
})
}
return values
}
Object.defineProperty(group, 'name', {
value: name
})
Object.defineProperty(group, 'values', {
get: function () {
return values
}
})
Object.defineProperty(group, 'n', {
get: function () {
return n
}
})
return group
}