Hi guys, I’m struggling to understand what’s being asked for here…
Recursive challenge
Write a recursive function, sum(arr, n) , that returns the sum of the first n elements of an array arr .
I know what the sum of numbers means.
I know that ‘n’ is the second parameter/argument.
When I look at the rules below…
Challenge guide picture
I’m not sure how the bottom two values have been arrived at. Can anyone help clarify this please.
Thanks for your help!
Challenge link
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion
sanity
November 30, 2021, 6:01pm
2
sum([1], 0) - sum of first 0 element(s) → 0
sum([2, 3, 4], 1) - sum of first 1 element(s) → 2
sum([2, 3, 4, 5], 3) - sum of first 3 element(s) → 2 + 3 + 4 → 9
3 Likes
Thank you @sanity . Just trying to understand the problem at this stage. I appreciate your help!
1 Like
system
Closed
June 1, 2022, 6:09am
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.