Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion

Tell us what’s happening:

Your code so far


function sum(arr, n) {
 // Only change code below this line
var sum = 0;
for (var i = 0; i < n; i++){
sum  += arr[i];}
return sum;

function sum(arr, n) {
 if(n <= 0) {
   return 1;
 } else {
   return sum(arr, n - 1) + arr[n - 1];
 }
}
 // Only change code above this line

}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0.

Challenge: Replace Loops using Recursion

Link to the challenge:

It has a for loop, in the solution you would not have to use it.