“Recursion JavaScript” 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

Rekursi dalam JavaScript

function recurse() {
    // function code
    recurse();
    // function code
}

recurse();
Restu Wahyu Saputra

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

Recursion JavaScript

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

    let nextNumber = fromNumber - 1;

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

Jawaban yang mirip dengan “Recursion JavaScript”

Pertanyaan yang mirip dengan “Recursion JavaScript”

Lebih banyak jawaban terkait untuk “Recursion JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya