we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "basic javascript 3a use recursion to create a countdown"
Emanuele
20 Jul 2017
1function countdown(n){
2  if (n < 1) {
3    return [];
4  } else {
5    const arr = countdown(n - 1);
6    arr.unshift(n);
7    return arr;
8  }
9}
10console.log(countdown(5)); // [5, 4, 3, 2, 1]