Timeline for answer to Javascript Recursion and Functions by CherryDT
Current License: CC BY-SA 4.0
Post Revisions
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 1, 2022 at 17:44 | comment | added | user17773050 | Let us continue this discussion in chat. | |
| Feb 1, 2022 at 17:43 | comment | added | CherryDT |
It sounds kind of right but I don't understand what you mean by "makes countup(0) and countup(1) true" and also "makes all the other functions true"... What do you mean by making a function true? It's kind of a nonsensical statement, from a JavaScript perspective (unless we were talking about some function isUserAdmin that returns true/false). Can you elaborate?
|
|
| Feb 1, 2022 at 17:39 | comment | added | user17773050 | Coming back to this think I understand it now. So in short, when n = 0 that makes 'countup(0)' and 'countup(1) true. Which continues the code '[ ].push(1)' which gives us the first '[1]'. And with that it makes all the other functions true which gives us the '[1,2,3,4,5]'? This is all done individually so like '[1].push(2) [1,2].push(3)'? | |
| Feb 1, 2022 at 16:25 | vote | accept | Community Bot | ||
| Feb 1, 2022 at 16:23 | vote | accept | Community Bot | ||
| Feb 1, 2022 at 16:25 | |||||
| Feb 1, 2022 at 16:19 | comment | added | CherryDT |
I still don't quite understand what you are asking. We have 5 times that return countArray happens. And every time before it there is a different n pushed into the array. See the explanation in steps listed above. I really recommend stepping through the code in the debugger yourself so you get a feel for it.
|
|
| Feb 1, 2022 at 16:18 | history | edited | CherryDT | CC BY-SA 4.0 |
added 189 characters in body
|
| Feb 1, 2022 at 16:15 | comment | added | user17773050 | Once the 'return countArray;' is performed. All the times where '(n < 1)' was false (2,3,4,5) gets added to the array? | |
| Feb 1, 2022 at 16:13 | comment | added | CherryDT |
I'm not sure what you mean when you say "rather than running the code again". What code are you referring to? Except for the case of countup(0) that returns [], the exact same code is ran every time (just with different local variables n and countArray²).
|
|
| Feb 1, 2022 at 16:12 | history | edited | CherryDT | CC BY-SA 4.0 |
added 396 characters in body
|
| Feb 1, 2022 at 16:06 | comment | added | user17773050 | Would I be right in saying this happens? After it runs for the first time, the "return countArray;" prints [1] then that is finished. We go back to when countup(n) n = 2. And rather than running the code again, that n is put into the array giving [1,2] etc till it goes to [1,2,3,4,5]? | |
| Feb 1, 2022 at 16:04 | history | edited | CherryDT | CC BY-SA 4.0 |
added 120 characters in body
|
| Feb 1, 2022 at 15:57 | history | edited | CherryDT | CC BY-SA 4.0 |
added 997 characters in body
|
| Feb 1, 2022 at 15:47 | comment | added | AGE | correct, to understand recursiveness you need to follow the flow of execution instead of focusing on the data itself | |
| Feb 1, 2022 at 15:45 | history | answered | CherryDT | CC BY-SA 4.0 |