Replace Loops using Recursion CHALLENGE

can someone help me , I can’t understand Recursion and what is the meaning of the sum of the first n

  **Your code so far**

function sum(arr, n) {
// Only change code below this line

// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36

Challenge: Replace Loops using Recursion

Link to the challenge:

Given arr looks like this: [a, b, c, d, e, f, g...]

n sum(arr, n)
0 0
1 a
2 a + b
3 a + b + c
4 a + b + c + d

And so on…

1 Like

As for the recursion, notice the pattern in the right column I listed above. Each result is the same as the result above it plus one more. In other words, you can rewrite a + b + c + d as sum(arr, 3) + d, likewise, you can rewrite a + b + c as sum(arr, 2) + c, and so on…