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.

What it basically says is that you need to sum all elements in an array up to the index provided which is n. For example your array is [2, 3, 4] and n in that example is 1 so index 0 represents 2 in that array and index 1 which is n represents 3 so you need to add 2 and 3.

Sum means add up the given values: “the sum of one and one and one is three”. Inclusive means a given range of values includes the first and last. “I’m taking my holiday between March the first and March the tenth inclusive” doesn’t mean the holiday is March 2nd to March 9th, but if you missed off the “inclusive” that may be what your HR department interprets your request as.

You have a collection of numbers, add them all up. Ranges of numbers are normally specified as either inclusive or non-inclusive in most programming contexts, as the distinction is important (some languages have special syntax for ranges, and they often explicitly specify the difference – for example 0..10 vs. 0...10).