Skip to content

Instantly share code, notes, and snippets.

@adi518
Created February 4, 2020 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adi518/c14898409f9a554d0819bf9d8dda2fea to your computer and use it in GitHub Desktop.
Save adi518/c14898409f9a554d0819bf9d8dda2fea to your computer and use it in GitHub Desktop.
function* fibonacci(limit = Infinity) {
let [prev, current] = [0, 1]
while (current < limit) {
;[prev, current] = [current, prev + current]
yield current
}
}
for (let i of fibonacci(30)) console.log(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment