Created
January 10, 2013 15:47
-
-
Save SomeKittens/4503031 to your computer and use it in GitHub Desktop.
Better fib generator in js
This file contains 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
//This one caches the previous results so we're not constantly re-calculating things we already know | |
//Fiddle: http://jsfiddle.net/somekittens/7R5bs/ | |
function fibDriver(n) { | |
return n === 0 ? 0 : fib(0, 1, n); | |
} | |
function fib(a, b, n) { | |
return n === 1 ? b : fib(b, a + b, n-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment