“JavaScript Rekursif” Kode Jawaban

Rekursi dalam JavaScript

var countdown = function(value) {
    if (value > 0) {
        console.log(value);
        return countdown(value - 1);
    } else {
        return value;
    }
};
countdown(10);
Ainul Sakib

JavaScript Rekursif

function fibonacciRecursive(n) {
	if (n < 2) {
    	return n
    }
  return fibonacciRecursive(n - 1) + fibonacciRecursive(n - 2)
}

fibonacciRecursive(8);
// 21
Dr.Strange

Fungsi Rekursif 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
Tiny Coders

Rekursi dalam JavaScript

Recusrion: 
function test(n){
    if(n>0){
        console.log(n)
        test(n-1)
    }
}
test(10)
test(20)
test(30)
Sandhya usa2021

Rekursi di 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]);
  }
}
Kon Ajang

Jawaban yang mirip dengan “JavaScript Rekursif”

Pertanyaan yang mirip dengan “JavaScript Rekursif”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya