Created
February 1, 2017 15:35
-
-
Save FreeFly19/880189bc22c918cef1096d2c76a245e8 to your computer and use it in GitHub Desktop.
Fib with caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fibonacci = (function () { | |
| var cache = []; | |
| return function fibo(n) { | |
| if (cache[n]) return cache[n]; | |
| return cache[n] = n == 0 ? 0 : | |
| n == 1 ? 1 : | |
| fibo(n-1) + fibo(n-2); | |
| }; | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment