Hi there!
To pass the countdown test I wrote this code.
function countdown(n){
if (n < 1){
return [];
} else {
const arr = [];
arr = countdown(n-1);
arr.unshift(n);
return arr;
}
}
And it didn’t pass…
After a long hour of frustration I pushed the “Get a Hint” button and find that the solution was this:
function countdown(n){
if (n < 1){
return [];
} else {
const arr = countdown(n-1);
arr.unshift(n);
return arr;
}
}
Can someone explain to me why the first one isn’t correct?
Thanks