-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (29 loc) · 692 Bytes
/
Copy pathindex.js
File metadata and controls
30 lines (29 loc) · 692 Bytes
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
"use strict";
(function (module) {
var combinations = module.exports = function* (array, count) {
if (array === undefined) {
array = [];
}
if (count === undefined) {
count = 0;
}
var keys = [];
var arrayLength = array.length;
var index = 0;
for (var i = 0; i < count; i++) {
keys.push(-1);
}
while (index >= 0) {
if (keys[index] < arrayLength - (count - index)) {
for (var key = keys[index] - index + 1; index < count; index++) {
keys[index] = key + index;
}
yield keys.map(function (c) {
return array[c];
});
} else {
index--;
}
}
};
})(module);