Created
April 5, 2020 04:22
-
-
Save dafujii/d98355360d95d471c67b96ddf22a595c to your computer and use it in GitHub Desktop.
TypeSctipt createFibonacciGenerator
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* createFibonacciGenerator() { | |
let a = 0n; | |
let b = 1n; | |
while (true) { | |
yield a; | |
[a, b] = [b, a + b]; | |
} | |
} | |
const fg = createFibonacciGenerator(); | |
for (let i = 0; i < 1000; i++) { | |
console.log(fg.next()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment