I am wondering if there's something I misunderstood here. The code is:
function countdown(n){
if(n < 1) return [];
let result = countdown(n - 1);
result.unshift(n);
return result;
}
I'm wondering why it can't be written like this:
function countdown(n){
if(n < 1) return [];
return countdown(n - 1).unshift(n);
}
This returns an error:
TypeError: countdown(...).unshift is not a function
Aren't both of them the same thing?