Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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]
 
PREVIOUS NEXT
Tagged: #Basic #Use #Recursion #Create #Countdown
ADD COMMENT
Topic
Name
5+4 =