Created
November 26, 2015 14:56
-
-
Save saxbophone/1dccc0f8b6deaedbebbb to your computer and use it in GitHub Desktop.
Fibonacci sequence generator in ES6
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* fibonacci(a=0, b=1) { | |
`This is a fibonacci sequence generator.` | |
yield a; | |
yield b; | |
let current = b; | |
let previous = a; | |
while (true) { | |
let next = previous + current; | |
previous = current; | |
current = next; | |
yield next; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment