Tell us what’s happening:
Guys, guys ! I really don’t understand how this algorithm comes up with these results !
Can someone ELI5 all the steps the program go through to return the number 63, with
this array values :
sum([5,10,15,18,5,1,9], 7);
I’m really stuck with this program, I have really no clue what it does !
Pliz send help. Thank you.
Your code so far
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
}
console.log(sum([5,10,15,18,5,1,9], 7));
= 63
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
.
Challenge: Replace Loops using Recursion
Link to the challenge: