I found this code on http://games.usvsth3m.com/javascript-under-pressure/ and I reach the 5th problem which requires to estimate the sum of all the integer in the list. The list may contains nested lists. So for a list [1,2,3,4,5] or [[1,2,3],4,5] the code below works but for a list [[[[[1]]]],2,3,4] does not. I try a lot of hours and I do not know to solve it. I need a hit plz.
function arraySum(i) {
var sum =0;
for (var id =0; id<i.length;id++){
if(typeof i[id]==='object'){
var ar = i[id];
for (var dd =0; dd<ar.length;dd++ ){
if(typeof ar[dd]==='number'){
sum+=parseInt(ar[dd]);
}
}
}
else
if(typeof i[id]==='number'){
sum+=parseInt(i[id]);
}
}
return sum;
}