|
1 | | -var combinations = (function () { |
| 1 | +(function (exports) { |
2 | 2 | 'use strict'; |
| 3 | + var combinations = (function () { |
| 4 | + var res = []; |
3 | 5 |
|
4 | | - var res = []; |
5 | | - |
6 | | - function combinations(arr, k, start, idx, current) { |
7 | | - if (idx === k) { |
8 | | - res.push(current.slice()); |
9 | | - return; |
10 | | - } |
11 | | - for (var i = start; i < arr.length; i += 1) { |
12 | | - current[idx] = arr[i]; |
13 | | - combinations(arr, k, i + 1, idx + 1, current); |
| 6 | + function combinations(arr, k, start, idx, current) { |
| 7 | + if (idx === k) { |
| 8 | + res.push(current.slice()); |
| 9 | + return; |
| 10 | + } |
| 11 | + for (var i = start; i < arr.length; i += 1) { |
| 12 | + current[idx] = arr[i]; |
| 13 | + combinations(arr, k, i + 1, idx + 1, current); |
| 14 | + } |
14 | 15 | } |
15 | | - } |
16 | 16 |
|
17 | | - return function (arr, k) { |
18 | | - res = []; |
19 | | - combinations(arr, k, 0, 0, []); |
20 | | - return res; |
21 | | - }; |
22 | | -}()); |
| 17 | + return function (arr, k) { |
| 18 | + res = []; |
| 19 | + combinations(arr, k, 0, 0, []); |
| 20 | + return res; |
| 21 | + }; |
| 22 | + }()); |
| 23 | + |
| 24 | + exports.combinations = combinations; |
| 25 | + |
| 26 | +}(typeof exports === 'undefined' ? window : exports)); |
0 commit comments