Skip to content

Instantly share code, notes, and snippets.

@esneko
Created April 26, 2019 07:46
Show Gist options
  • Save esneko/c9f2457ff97d0fa6cab0f38dcad06b3e to your computer and use it in GitHub Desktop.
Save esneko/c9f2457ff97d0fa6cab0f38dcad06b3e to your computer and use it in GitHub Desktop.
Generators
function* fibonacci() {
let [prev, curr] = [0, 1]
while (true) {
[prev, curr] = [curr, prev + curr]
yield curr
}
}
for (let n of fibonacci()) {
console.log(n)
if (n >= 10) {
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment