function sum(arr, n) {
// Only change code below this line
if (n <= 0) {
return 0;
// Only change code above this line
} else {
return sum(arr, n - 1) + arr[n - 1];
}
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.
Recursion has been discussed so many times in this forum that I’m not exactly excited to type out a long explanation here Search for “recursion” using the search icon at the top of the forums here and you will find a ton of links to previous discussions about recursion.
But maybe someone else will feel differently and type something up here?
The addition sign in this return statement adds two numbers. Using my example above, what is the value of arr[n-1]? And then you are adding that value to what is returned by the function call sum(arr, n - 1). Again, using my example above, fill in the actual values for the return statement in the else block when you call it for the first time.