Skip to content

Commit b4bf749

Browse files
committed
Exports cartesian product
1 parent 4f497dd commit b4bf749

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
var cartesianProduct = (function () {
1+
(function (exports) {
22
'use strict';
3-
var result;
3+
var cartesianProduct = (function () {
4+
var result;
45

5-
function cartesianProduct(sets, index, current) {
6-
if (index === sets.length) {
7-
return result.push(current.slice());
6+
function cartesianProduct(sets, index, current) {
7+
if (index === sets.length) {
8+
return result.push(current.slice());
9+
}
10+
for (var i = 0; i < sets[index].length; i += 1) {
11+
current[index] = sets[index][i];
12+
cartesianProduct(sets, index + 1, current);
13+
}
814
}
9-
for (var i = 0; i < sets[index].length; i += 1) {
10-
current[index] = sets[index][i];
11-
cartesianProduct(sets, index + 1, current);
12-
}
13-
}
1415

15-
return function (sets) {
16-
result = [];
17-
cartesianProduct(sets, 0, []);
18-
return result;
19-
};
20-
}());
16+
return function (sets) {
17+
result = [];
18+
cartesianProduct(sets, 0, []);
19+
return result;
20+
};
21+
}());
22+
23+
exports.cartesianProduct = cartesianProduct;
2124

25+
}(typeof exports === 'undefined' ? window : exports));

0 commit comments

Comments
 (0)