Hi everyone, this is my first post, happy to be here at freecodecamp, awesome site!
After doing some forum searching, I am slowing wrapping my head around recursion, but solution 4 is the closest thing to coding black magic since 0x5F3759DF.
To recap, the solution is:
function countdown(n){
return n < 1 ? [] : [n, ...countdown(n - 1)];
}
Could someone please explain this, especially the effect of the ellipses?
Thank you!
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
I am as yet unfamiliar with ternaries, but will investigate further, along with spread contents (I hope that is what I google).
EDIT: Actually the ternary was fine, I just didn’t recall ‘?’ being called that