/**
* Example: 0,1,1,2,3,5,8,13,21 dst
*/
const start = performance.now();
function memoize(fn){
const localCache = {}
return function(...args){
if (localCache[args]){
return localCache[args]
}
const result = fn.apply(this, args);
localCache[args] = result;
return result;
}
}
function slowFibo(n){
if (n < 2){
return n
}
return fibo(n-1) + fibo(n-2);
}
// Fast fibo
const fibo = memoize(slowFibo);
console.log(fibo(40))
// Slow fibo
// const fibo = slowFibo;
// console.log(fibo(40))
const end = performance.now();
console.log(`Executed ${((end - start)/1000).toFixed(5)} Seconds`)