Recursion challenge - meaning of some codes

Hi, could someone explain me the meaning of sum([2, 3, 4], 1). I attach the screen shot.

also I dont understand the meaning of this code :
return sum(arr, n - 1) + arr[n - 1]


Your code so far

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

 // Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5.

Challenge: Replace Loops using Recursion

Link to the challenge:

it’s a couple of times I see you asking what a function call means, maybe you need to review some basics about functions?

Hi @SARA1985!

This is one of the test cases where [2,3,4] is the array while 1 represents n.

If we use the same test case you mentioned earlier we could plug in those values.

return sum([2,3,4], 1 - 1) + arr[1- 1]

I would suggest trying out one of these cases in a debugger so you can see step by step what is going on.

This is a screenshot from my debugger for this function

Debuggers are powerful and essential tools in programming. They reveal what is actually going on with your code.

I am also going to provide some more resources on recursion since it is a tricky topic.

1 Like

@jwilkins.oboeThank u so much Jessica for response and videos.