Skip to content

Instantly share code, notes, and snippets.

@eNV25
eNV25 / fibonacci-generator.js
Last active May 17, 2021 07:35 — forked from jfairbank/fibonacci-generator.js
Fibonacci ES6 Generator
export function *fibonacci(n) {
const infinite = !n && n !== 0;
let current = 0n;
let next = 1n;
while (infinite || n--) {
yield current;
[current, next] = [next, current + next];
}
}