Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Better fib generator in js
//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