When I call this recursive function with --> multiply( [ 1 , 2 , 3 , 4 , 5 ] , 3 ) , I get NaN. What is the reason behind?
let multiply = function (arr, num) {
if (num <= 0) {
return 1;
}
return arr[num - 1] * multiply([1, 2, 3, 4, 5], num - 1);
}
console.log(multiply( [ 1 , 2 , 3 , 4 , 5 ] , 3 ));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…