Javascript code to find nth fibonnnaci term

Javascript code to find nth fibonnnaci term

Here,Is a js program to find nth fibonnaci number.


const fibonacci = (n,memo = []) => {
  if (n in memo) return memo[n];
  if (n<=2) return 1;
  memo[n] =  fibonacci(n-1,memo) + fibonacci(n-2,memo);
  return memo[n];

}

Post a Comment

0 Comments