Tell us what’s happening:
Could someone please explain to me, in the most simple and non-mathematical terms, what this sentence means; " Write a recursive function, sum(arr, n)
, that returns the sum of the elements from 0
to n
inclusive in an array arr
. Hints: sum([1], 0)
should equal 1, sum([2, 3, 4], 1)
should equal 5.
I’m not looking for an explanation of recursion or how for-loops work. I’m looking for a simple explanation of the mathematical process going on in the highlighted section that returns the sum of the elements from 0
to n
inclusive in an array arr
. Pretty simple sentence really but I’m native English and this makes no sense to me, it has been many many years since I was taught basic maths.
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/80.0.3987.87 Safari/537.36
.
Challenge: Replace Loops using Recursion
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion