Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Combinations/JavaScript/combinations-3.js
Normal file
29
Task/Combinations/JavaScript/combinations-3.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
(function () {
|
||||
|
||||
function comb(n, lst) {
|
||||
if (!n) return [[]];
|
||||
if (!lst.length) return [];
|
||||
|
||||
var x = lst[0],
|
||||
xs = lst.slice(1);
|
||||
|
||||
return comb(n - 1, xs).map(function (t) {
|
||||
return [x].concat(t);
|
||||
}).concat(comb(n, xs));
|
||||
}
|
||||
|
||||
|
||||
// [m..n]
|
||||
function range(m, n) {
|
||||
return Array.apply(null, Array(n - m + 1)).map(function (x, i) {
|
||||
return m + i;
|
||||
});
|
||||
}
|
||||
|
||||
return comb(3, range(0, 4))
|
||||
|
||||
.map(function (x) {
|
||||
return x.join(' ');
|
||||
}).join('\n');
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue