fibonacci Recursive v2

Fibonacci Recursive v2

Print out the n-th entry in the fibonacci series. The fibonacci series is an ordering of numbers where each number is the sum of the preceeding two.

Example:
findFactorialRecurative(5)} 24


function fib(n) {
  if (n < 2) {
    return n;
  }
  return fib(n-1) + fib (n-2);
}
fib(8) 21


We create a function fib with parameter of n

We check wheter n is less than 2 and if it is we return to n.

In the end we return fib(n-1) + fib (n-1)

comments powered by Disqus