Fibonacci

Fibonacci

In mathematics, the Fibonacci numbers, commonly denoted Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. ___

##For Example
console.log(recursive(6));=> 8 console.log(recursive(6));=> 89

##



let recursive = function (n) {
  if (n <= 2) {
    return 1;
  } else {
    return recursive(n - 1) + recursive(n - 2);
  }
};

console.log(recursive(6));






We create name function called recursive with the value of n

if ( n <=2 ) { return 1;}

if the parameter is less or equal to 2 we return 1

else we recurisvly return recursive(n - 1) + recursive (n - 2)



comments powered by Disqus