ERROR : <--- JS stacktrace ---> Cannot get stack trace in GC. FATAL ERROR: Scavenger: semi-space copy Allocation failed - process out of memory.
Out of Memory ? I have a JS code which calculate all combinations of an array to a sum =610. But the code works fine up to target 200 later it breaks. Can anyone Help me to get desired Result.
function combinationSum(candidates, target) {
var result = [];
if(candidates == null || candidates.length == 0) return result;
var current = [];
candidates.sort();
combinationSumHelper(candidates, target, 0, current, result);
return result;
}
function combinationSumHelper(candidates, target, j, curr, result){
if(target == 0){
var temp = curr.slice();
result.push(temp);
return;
}
for(var i=j; i<candidates.length; i++){
if(target < candidates[i])
return;
curr.push(candidates[i]);
combinationSumHelper(candidates, target - candidates[i], i, curr, result);
curr.pop();
}
}
console.log(combinationSum([1,2,3,4,5,6],610).length);