Fibonacci

Run Settings
LanguageTypeScript
Language Version
Run Command
/** * Example: 0,1,1,2,3,5,8,13,21 dst */ const start = performance.now(); function memoize(fn: (a:number) => number){ 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: number):number{ if (n < 2){ return n } return fibo(n-1) + fibo(n-2); } const fibo = memoize(slowFibo); console.log(fibo(40)) const end = performance.now(); console.log(`Executed ${((end - start)/1000).toFixed(5)} Seconds`)
Editor Settings
Theme
Key bindings
Full width
Lines