Replace Loops using Recursion

I had to step away from trying to learn coding for quite a while now. But I am trying to get back into it. I feel as I can do most of it. But am not really grasping it . Its like I know the letters of the alphabet, can put the letter together to make the right words. But feel as I am not sure why.
I did manage to pass Replace Loops using Recursion /*

function sum(arr, n) {

// Only change code below this line

if( n <=0 ){

return 0;



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


// Only change code above this line

*/ Maybe this is a vague thing to ask But I really don’t understand the n-1

We have blurred this solution so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

w.r.t. the n-1, all it is doing is reducing the size of the problem
That is the principal behind recursion. Do one thing only each time the function is called, the call yourself but with a little bit less to do…

Thank you. Like I said some how I can do it but still convince myself I am not really grasping the How. Again Thank you

Recursion is tricky. Part of the trickiness is understanding that function calls are independent.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.