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

countdown recursion javascript

const recursiveRangeSum = (num, total = 0) => {  if (num <= 0) {    return total;  }  return recursiveRangeSum(num - 1, total + num);};
Comment

PREVIOUS NEXT
Code Example
Javascript :: ReferenceError: __dirname is not defined 
Javascript :: jquery accept only excel file 
Javascript :: regular expression for numbers and comma only 
Javascript :: import redux thunk 
Javascript :: How to get the browser to navigate to a URL in JavaScript 
Javascript :: jquery get screen height 
Javascript :: Use jQuery in Console 
Javascript :: update node.js dependencies 
Javascript :: colors in node js console 
Javascript :: Finished. Please run Mix again. 
Javascript :: city regex pattern 
Javascript :: react native password input 
Javascript :: java scripyt code to edit webapge 
Javascript :: js split array in half 
Javascript :: download jquery 3.1.1 
Javascript :: objectid is not defined node js mongodb 
Javascript :: jQuery and changing the input field type 
Javascript :: javascript uppercase first letter 
Javascript :: JS Fetch API Post Request 
Javascript :: how to use another port in angular 
Javascript :: angular clone array without reference 
Javascript :: how to check if local storage variable exists in javascript 
Javascript :: how to use lodash in angular 
Javascript :: node-fetch post request example 
Javascript :: excel date to javascript date 
Javascript :: Javascript get random item from array 
Javascript :: javascript float element right 
Javascript :: js post 
Javascript :: check if date time string is invalid date js 
Javascript :: JS get random number between 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =