I can't seem to figure out what's wrong with this code -> keeps throwing a "Maximum call stack size exceeded" error.
function arrayIntSum(array) {
if (array === []){
return 0;
}
else return array.shift() + arrayIntSum(array);
}
Javascript objects are compared by reference.
[] creates a new array instance, which will will never equal your variable.
You want to check the length.
You should check by this way : a.length==0
you compared a with [] , being a '[]' literal, it has different memory space. and a has different memory space. So they are never equal. so recursion cross its limit
array.reduce(function(sum, n) { return sum + n; }, 0);