Skip to content

Commit a3984f5

Browse files
committed
Exports variations with repetions
1 parent b4bf749 commit a3984f5

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/combinatorics/cartesianproduct.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(function (exports) {
22
'use strict';
3+
34
var cartesianProduct = (function () {
45
var result;
56

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
var variationsWithRepetion = (function () {
1+
(function (exports) {
22
'use strict';
33

4-
var res;
4+
var variationsWithRepetion = (function () {
5+
var res;
56

6-
function variations(arr, k, index, current) {
7-
if (k === index) {
8-
return res.push(current.slice());
7+
function variations(arr, k, index, current) {
8+
if (k === index) {
9+
return res.push(current.slice());
10+
}
11+
for (var i = 0; i < arr.length; i += 1) {
12+
current[index] = arr[i];
13+
variations(arr, k, index + 1, current);
14+
}
915
}
10-
for (var i = 0; i < arr.length; i += 1) {
11-
current[index] = arr[i];
12-
variations(arr, k, index + 1, current);
13-
}
14-
}
1516

16-
return function (arr, k) {
17-
res = [];
18-
variations(arr, k, 0, []);
19-
var temp = res;
20-
res = undefined;
21-
return temp;
22-
};
23-
}());
17+
return function (arr, k) {
18+
res = [];
19+
variations(arr, k, 0, []);
20+
var temp = res;
21+
res = undefined;
22+
return temp;
23+
};
24+
}());
25+
26+
exports.variationsWithRepetion = variationsWithRepetion;
2427

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

0 commit comments

Comments
 (0)