js 有长度但是没有数据,考虑到是可能是异步问题或者深拷贝,但是不知道怎么修改
let candidates = [2, 3, 6, 7]
let target = 7
let path = []
let sum = 0
let startindex = 0
var res = []
function backTracing(candidates, target, sum, startindex) {
if (sum > target) {
return
}
if (sum === target) {
res.push(path)
console.log(path);
return res
}
for (let i = startindex; i < candidates.length; i++) {
path.push(candidates[i])
sum += candidates[i]
// console.log(sum);
backTracing(candidates, target, sum, i)
sum -= candidates[i]
path.pop()
}
return res
}
abc = backTracing(candidates, target, sum, startindex)
console.log(abc);let candidates = [2, 3, 6, 7]
let target = 7
let path = []
let sum = 0
let startindex = 0
var res = []
function backTracing(candidates, target, sum, startindex) {
if (sum > target) {
return
}
if (sum === target) {
res.push(path)
console.log(path);
return res
}
for (let i = startindex; i < candidates.length; i++) {
path.push(candidates[i])
sum += candidates[i]
// console.log(sum);
backTracing(candidates, target, sum, i)
sum -= candidates[i]
path.pop()
}
return res
}
abc = backTracing(candidates, target, sum, startindex)
console.log(abc);
运行结果及报错内容
我想要达到的结果