Skip to content

Instantly share code, notes, and snippets.

@neharkarvishal
Created November 28, 2020 11:59
Show Gist options
  • Save neharkarvishal/dc5f97f5e512204e89a7b705c0930a76 to your computer and use it in GitHub Desktop.
Save neharkarvishal/dc5f97f5e512204e89a7b705c0930a76 to your computer and use it in GitHub Desktop.
/**
* fibonacciGenerator.js
* tags: { JavaScript, Generator, Iterator }
*/
function* fibonacciGenerator() {
var [prev, curr] = [0, 1]
while(true) {
[prev, curr] = [curr, prev + curr]
yield curr
}
}
for(n of fibonacciGenerator()) {
console.log({n})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment