Answers for "javascript recursion countdown"

3

Basic JavaScript: Use Recursion to Create a Countdown

function countdown(n){
  if (n < 1) {
    return [];
  } else {
    const arr = countdown(n - 1);
    arr.unshift(n);
    return arr;
  }
}
console.log(countdown(5)); // [5, 4, 3, 2, 1]
Posted by: Guest on December-20-2019

Code answers related to "javascript recursion countdown"

Code answers related to "Javascript"

Browse Popular Code Answers by Language