Find the fibonacci of f(n) JavaScript

Abhijit chakra
Oct 13, 2020

Here we will find the fibonacci of a number n f(n) = f(n-1) + f(n-2) while n>2 using dynamic programming top down (memorization) technique

/**

* find the fibonacci of a number using dynamic programming

* Top Down Appach (memorisation)

*/

function findFib(n,cache){

cache = []

if(n<2){

return n

}

if(!cache[n]){

return cache[n]= findFib(n-1,cache)+findFib(n-2,cache)

}

return cache[n]

}

console.log(findFib(6))

The best book for cracking coding interview in my experience , available on amazon, link is below book

The best book for cracking coding interview in my experience , available on amazon, link is below book

https://amzn.to/3cFjyGy

--

--