Hi, I have been struggling with this problem for 2 days now, and I just want to see the solution so I can learn what I am missing. The recursion is very hard for me to understand.
Your code so far
function sum(arr, n) {
// Only change code below this line
if (n<=1) {
return 0;
} else {
sum[n - 1];
}
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 13310.76.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.108 Safari/537.36.
Sorry to hear that you’ve been struggling with this. If you click on “Get Help” then “Get a Hint”, you’ll be taken to a post with hints + possible solutions. You can find a solution there to help guide and direct you for this particular challenge.
I ran the solution from the guide post @darren-stoll linked for you against the tests in the challenge, and everything passes on my end. The solution appears to be correct. Can you share your current code again?
I am glad you were able to solve it! I do, however, strongly encourage that you spend the time to understand recursion. It’s a powerful tool to have in your kit.
First off, I am glad that you were able to figure out the solution. I do agree with @nhcarrigan’s advice about spending extra time on this topic because it will come up again later on in the javascript section.
This is a helpful video explaining how recursion works and what is actually happening inside the computer.
I would also highly suggest that you watch Colt’s other video on call stacks as well
That first video really REALLY helped me understand what was happening! Thank you so much. I did not realize that all of these returns were pending until the base case was hit. I made this account just to express my gratitude. I passed the challenge just fine but did not really grok what was going on.