Basic JS Replace Loops using Recursion not passing

Tell us what’s happening:
I couldn’t get why this condition is true in the challenge:

return sum(arr,n-1) + arr[n-1];

I thought that it can be written as:

return sum(arr,n-1) + arr[n];


return sum(arr,n) + arr[n-1];

Your code so far

function sum(arr, n) {
// Only change code below this line
return 0;
} else{
return sum(arr,n-1) + arr[n-1];
// Only change code above this line

var a = [1,23,3,4,5];

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Replace Loops using Recursion

Link to the challenge:

this will make a stack overflow error

with this you never sum arr[n]

this should be the correct one

but there is an other issue:

with this you are never summing arr[0] as when n is 0 you just add 0 instead of the first item in the array