Hello, i wrote the code below at first without the … in const count = [n, **…**countdown(n-1)]; after seeing the hint I added it and passed the challenge but I still don’t understand what does this … mean or do
// Only change code below this line
function countdown(n){
if (n < 1){
return [ ];
} else {
const count = [n, **...**countdown(n-1)];
return count;
}
}
// Only change code above this line
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0
Recursion is a tough topic, especially for beginners. Most people get stopped up on this.
If you search the forum, you will find many detailed explanations of it and even this specific challenge. Please take a look at them and if you still do not understand, then please come back and ask what is stopping you.
Used in this context, ... is the spread syntax. From this documentation:
“It is commonly used when you want to add a new item to a local data store, or display all stored items plus a new addition. A very simple version of this kind of action could look like so:”
let numberStore = [0, 1, 2];
let newNumber = 12;
numberStore = [...numberStore, newNumber];
Does that look similar to what the else block in your countdown code is doing?