My apologies for the confusing question, but let's delve into it:
function sum(arr, n) {
// Only change code below this line
if (n <= 0) {
return 0;
} else {
return sum(arr, n - 1) + arr[n - 1];
}
// Only change code above this line
}
var a = sum([2, 3, 4], 1);
console.log(a);
After calling a
, the result will be 2. What I'm unsure about is which value should replace arr
in the sum(arr, n - 1)
. Should it not be something like arr[]
so that I can select one of the three numbers from the array instead?