为什么这个函数返回undefined
?
内部函数返回正确的值。
function arraySum(i) {
// i will be an array, containing integers, strings and/or arrays like itself.
// Sum all the integers you find, anywhere in the nest of arrays.
(function (s, y) {
if (!y || y.length < 1) {
//console.log(s);
// s is the correct value
return s;
} else {
arguments.callee(s + y[0], y.slice(1));
}
})(0, i);
}
var x = [1, 2, 3, 4, 5];
arraySum(x);