Created
November 13, 2015 13:48
-
-
Save dividead/0cae90f8b4969dcfa3ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tens(a, t, r = []){ | |
if (t < 0) return | |
for(let i of a){ | |
if(i == t) r.push([i]) | |
let s = tens(a.slice(a.indexOf(i) + 1), t - i) | |
if(s) for(let x of s) r.push([i].concat(x)) | |
} | |
return r | |
} | |
let arr = [7, 10, 2, 5, 3, 1] | |
let arr2 = [ 1, 5, 6, 4, 2, 8] | |
console.log(tens(arr, 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment