Tell us what’s happening:
The Question: Write a recursive function, sum(arr, n)
, that returns the sum of the first n
elements of an array arr
.
How are we meant to discern what n
represents from this question? I cannot see any indication of what n
is meant to represent, index? Is this question just poorly written, or dose, first n
elements, have a specific meaning? I don’t want to be just told what it means, I want to know how to discern what it means from this question.
n
represents number of elements.
Your code so far
function sum(arr, n) {
// Only change code below this line
if (n <= o) {
return 0;
}
else {
return num(n + arr[])
}
// 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/107.0.0.0 Safari/537.36 Edg/107.0.1418.62
Challenge: Basic JavaScript - Replace Loops using Recursion
Link to the challenge: