Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

recursion javascript

function countDown(fromNumber) {
    console.log(fromNumber);

    let nextNumber = fromNumber - 1;

    if (nextNumber > 0) {
        countDown(nextNumber);
    }
}
countDown(3);
Code language: JavaScript (javascript)
Comment

recursive function javascript

/*
Recursion is when a function calls itself until someone stops it. 
If no one stops it then it'll recurse (call itself) forever.
*/

// program to count down numbers to 1
function countDown(number) {
    // display the number
    console.log(number);
    // decrease the number value
    const newNumber = number - 1;
    // base case
    if (newNumber > 0) {
        countDown(newNumber);
    }
}

countDown(4);
// Out put: 
4
3
2
1
Comment

Recursion In DOM

function walkTree(node) {
  if (node == null) //
    return;
  // do something with node
  for (var i = 0; i < node.childNodes.length; i++) {
    walkTree(node.childNodes[i]);
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: find js 
Javascript :: get query params react 
Javascript :: sample docker for node js 
Javascript :: downgrade node version 
Javascript :: sort in mongoose aggregate lookup 
Javascript :: get values inside json node js 
Javascript :: Find the stray number 
Javascript :: js split string every n characters 
Javascript :: get the whole value of a number javascript 
Javascript :: count documents mongoose 
Javascript :: swap function javascript 
Javascript :: js fibonacci sequence 
Javascript :: es6 convert array to object 
Javascript :: node js check if called from command line 
Javascript :: sequelize migration skeleton 
Javascript :: select element by id 
Javascript :: java json string to map 
Javascript :: javascript detect tab leave 
Javascript :: redirect after print javascript 
Javascript :: javascript duplicate an array 
Javascript :: how to seperate words seperated by commas using javascript 
Javascript :: set background image URL jQuery 
Javascript :: material app routes 
Javascript :: moment js get french time 20:00:00 
Javascript :: js combine arrays 
Javascript :: remove element from array javascript by index 
Javascript :: use jq to update json file 
Javascript :: reverse javascript 
Javascript :: print whole array javascript 
Javascript :: how to know if select input has been selected in js 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =