# Replace Loops using Recursion

I really need a feed back on my explanations especially on 2) and 3). I just want to confirm if I understood it correctly or no since I am a newbie.
This is a freeCodeCamp challenge which was really challenging for me because I have no experience with JS before. It goes as below.
Write a recursive function, sum(arr, n), that returns the sum of the first n elements of an array arr.

```function sum(arr, n) {
if(n <= 0) {
return 0;
} else {
return sum(arr, n - 1) + arr[n - 1];
}
}

/* 1) sum(, 0) should equal 0.
2) sum([2, 3, 4], 1) should equal 2.
3) sum([2, 3, 4, 5], 3) should equal 9. */

/* My explanations are down below */

/*
Explanation 1)
sum(, 0) should equal 0.
n is less or equal to 0 so line 2 works and returns 0 at line 3.
*/

/*  Explanation 2)
sum([2, 3, 4], 1) should equal 2
n is not less or equal to 0 so it will not return 0 according to line 2. We move to line 5.
*return sum(arr, n - 1) + arr[n - 1];
=>  return sum([2, 3, 4], 1 - 1) + arr[1 - 1];
=>  return sum([2, 3, 4], 0) + arr => n is less or equal to 0 so it will return zero according to line 2.
=>  return 0 + arr
=>  Since arr is equals to 2
=>  return 0 + 2;
=>  2
*/

/*  Explanation 3)
sum([2, 3, 4, 5], 3) should equal 9
n is not less or equal to 0 so it will not return 0 according to line 2. We move to line 5.
*return sum(arr, n - 1) + arr[n - 1];
=>  return sum([2, 3, 4, 5], 3 - 1) + arr[3 - 1];
=>  return sum([2, 3, 4, 5], 2) + arr; => n is 2, not less or equal to 0 so go back to line 5 + arr.
=>  return sum(arr, n - 1) + arr[n - 1] + arr;
=>  return sum([2, 3, 4, 5], 2 - 1) + arr[2 - 1] + arr;
=>  return sum([2, 3, 4, 5], 1) + arr + arr; => n is 1, not less or equal to 0 so goes back to line 5 arr + arr.
=>  return sum(arr, n - 1) + arr[n - 1] + arr + arr;
=>  return sum([2, 3, 4, 5], 1 - 1) + arr[1 - 1] + arr + arr;
=>  return sum([2, 3, 4, 5], 0) + arr  + arr + arr;
=>  return 0 + arr + arr + arr;
=>  in our array, arr is 2, arr is 3, arr is 4.
=>  0 + 2 + 3 + 4
=>  5 + 4
=>  returns 9
*/```

```const sum = (arr,n) => --n<0 ? 0 : sum(arr,n) +arr[n]
`.as-console-wrapper { max-height: 100% !important; top: 0; }`