Search
 
SCRIPT & CODE EXAMPLE
 

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]
Comment

Use Recursion to Create a Countdown

function countdown(n){
   return n < 1 ? [] : [n].concat(countdown(n - 1));
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery cancel ajax request on click 
Javascript :: PayloadTooLargeError: request entity too large 
Javascript :: react interpolation string html 
Javascript :: sqlite3 multithreading nodejs 
Javascript :: nextjs tailwind 
Javascript :: javascript play sound onclick 
Javascript :: jquery append once 
Javascript :: slice until character javascript 
Javascript :: javascript max safe integer 
Javascript :: JavaScript create ul li from array 
Javascript :: unique values from array of objects 
Javascript :: jquery validation on button click 
Javascript :: how to find out if mongoose is connected or not 
Javascript :: click a link using jquery 
Javascript :: setting proxy in npm 
Javascript :: javascript get last character of string 
Javascript :: fs in angular 
Javascript :: js foreach determine if last 
Javascript :: javascript store in localstorage 
Javascript :: react native port 
Javascript :: react data attributes event 
Javascript :: remove disable attr jquery 
Javascript :: send message to all servers discord.js 
Javascript :: remove item jquery 
Javascript :: localstorage read all key 
Javascript :: Get Substring between two characters using javascript 
Javascript :: getting the distance fo an element from the top jquery 
Javascript :: how to make javascript make things disappear 
Javascript :: javascript 5 digit random number 
Javascript :: jquery change picture source 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =