Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Latest commit

 

History

History

Recursion

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

Recursion in JavaScript

Recursion in JavaScript

Factorial of a Number

function factorial(n){
    if(n === 0)
        return 1;
    return n * factorial(n - 1);
}

console.log(factorial(8));

Sum of Array

function sumOfArrays(arr, n){
    if(n === 0){
        return 0;
    }

    return arr[n - 1] + sumOfArrays(arr, n - 1);
}

console.log(sumOfArrays([1, 2, 3, 4, 5], 5));

Fibonacci Number

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

console.log(fibo(5));

Practice Questions (solve using recursion):

  • Check whether a string is palindrome or not
  • Create pow(x, n) function which returns x^n
  • Create a function which returns the sum of digits of a number (e.g., sumOfDigits(453) is 12)
  • Create a function which returns the number of digits in a number (e.g., countDigits(453) is 3)
  • Create a function to find the LCM of two numbers
  • Create a function to find the GCD of two numbers
  • Create a function to reverse a string