Created
November 5, 2015 23:39
-
-
Save josephjunker/1d5117f197e2bdd90ca2 to your computer and use it in GitHub Desktop.
an even worse fibbonacci sequence generator
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
function fib(count) { | |
function f(list) { if(!count) return list; x(); count--; return f(list); } | |
function x() { | |
var list = f.arguments[0]; | |
list.push((list[list.length - 1] || 1) + (list[list.length - 2] || 0)); | |
} | |
if (count < 0) count = 0; | |
return f([]); | |
} | |
fib(5); // returns [ 1, 1, 2, 3, 5 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment