Created
November 2, 2015 19:21
-
-
Save owen-d/015a517f46ad80092629 to your computer and use it in GitHub Desktop.
ez fibonacci
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
function fib() { | |
var head = 0; | |
var tail = 0; | |
return function() { | |
var res = head + tail; | |
//just for the beginning, so we get 2 rounds with a result of 1 | |
if (!res) { | |
head = 1; | |
return head; | |
} | |
tail = head; | |
head = res; | |
return res; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment