Created
May 22, 2012 17:56
-
-
Save git2samus/2770593 to your computer and use it in GitHub Desktop.
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 fibonacciFactory() { | |
| var a=0, b=1; | |
| return function() { | |
| var next=a+b; | |
| a=b, b=next; | |
| return a; | |
| }; | |
| }; | |
| undefined | |
| > next_fibonacci = fibonacciFactory(); | |
| function () { var next=a+b; a=b, b=next; return a; } | |
| > next_fibonacci(); | |
| 1 | |
| > next_fibonacci(); | |
| 1 | |
| > next_fibonacci(); | |
| 2 | |
| > next_fibonacci(); | |
| 3 | |
| > next_fibonacci(); | |
| 5 | |
| > next_fibonacci(); | |
| 8 | |
| > next_fibonacci(); | |
| 13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment