var combine = function(n, k, m) {
function generation(n, k, start, s) {
if (s.length === k) {
let sum = 0
for(let i = 0; i < k; i++) {
sum += s[i]
}
if (sum === m) {
res.push(s.slice())
}
return
}
for(let i = start; i < n.length; i++) {
s.push(n[i])
generation(n, k, i + 1, s)
console.log(s, res)
s.pop()
}
return
}
let res = []
let s = []
if (n.length <= 0 || k > n.length || k <= 0) {
return res
}
generation(n, k, 0, s)
return res
};
var combine = function(n, k, m) { function generation(n, k, start, s) { if (s.length === k) { let sum = 0 for(let i = 0; i < k; i++) { sum += s[i] } if (sum === m) { res.push(s.slice()) } return } for(let i = start; i < n.length; i++) { s.push(n[i]) generation(n, k, i + 1, s) console.log(s, res) s.pop() } return } let res = [] let s = [] if (n.length <= 0 || k > n.length || k <= 0) { return res } generation(n, k, 0, s) return res };