Skip to content

Instantly share code, notes, and snippets.

@mollymorphic
Last active December 11, 2015 20:49
Show Gist options
  • Save mollymorphic/4658391 to your computer and use it in GitHub Desktop.
Save mollymorphic/4658391 to your computer and use it in GitHub Desktop.
Clojuresque Fibs in JS.
function allfibs(end) {
var x = 0, y = 1, count = 1;
yield 1;
while (count++ < end) {
[x,y] = [y,x + y];
yield y;
}
}
function fibs(x) {
return [ i for (i in allfibs(x)) ]
}
fibs(5) // [1,1,2,3,5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment