The combinationSum function is returning an empty resultArr. When checking the ds array with console.log, it shows the correct answer, but for some reason, the final output array ends up being [[],[]].
var combinationSum = function(candidates, target) {
const resultArr = []
function combinationSumHelper(idx, candidates, ds, target){
if(idx === candidates.length){ // base case
if(target === 0){
console.log(ds) *// The console log here displays the right answer, but somehow the resultArr returned by combinationSum remains empty*
resultArr.push(ds)
}
return
}
if(candidates[idx] <= target){
ds.push(candidates[idx])
combinationSumHelper(idx, candidates, ds, target - candidates[idx])
ds.pop()
}
combinationSumHelper(idx+1, candidates, ds, target)
}
combinationSumHelper(0, candidates, [], target)
return resultArr
};
console.log(combinationSum([2,3,6,7], 7))
OUTPUT: [ [], [] ]
EXPECTED OUTPUT: [[2,2,3],[7]]
STDOUT: [ 2, 2, 3 ] [ 7 ]