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]
Thanks
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:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
ilenia
January 3, 2021, 3:00pm
2
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.
> "To understand recursion, one must first understand recursion" - Unknown If you're like me then you probably didn't understood recursion the first time you read about it. For me, it was because 1. recursion is a hard concept in itself, and ...
1 Like
@jwilkins.oboeThank u so much Jessica for response and videos.