Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use ES6 generator to generate infinite fibonacci series
function *calcFib () {
let n = 0
let fib = function(v) {
return v <= 1 ? v : fib(v - 1) + fib(v - 2)
}
while (true) yield fib(n++)
}
let generator = calcFib()
generator.next() // 0
generator.next() // 1
generator.next() // 1
generator.next() // ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.