Last active
September 27, 2015 08:27
-
-
Save israelst/1240259 to your computer and use it in GitHub Desktop.
A lazy fibonacci example written in javascript
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 create_fibonacci(){ | |
var n1 = -1, | |
n2 = 1, | |
n = 0; | |
return function(){ | |
n = n1 + n2; | |
n1 = n2; | |
n2 = n; | |
return n; | |
} | |
} | |
var fib = create_fibonacci(); | |
for(var i = 0; i<=15; i++){ | |
console.log(fib()); | |
} |
juanplopes
commented
Sep 25, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment