function* fibonacci() {
let [a, b] = [0, 1];
while (true) {
yield a;
[a, b] = [b, a + b];
}
}
const fib = fibonacci();
const first5 = Array.from({ length: 5 }, () => fib.next().value);
console.log(first5); function* fibonacci() {
let [a, b] = [0, 1];
while (true) {
yield a;
[a, b] = [b, a + b];
}
}
const fib = fibonacci();
const first5 = Array.from({ length: 5 }, () => fib.next().value);
console.log(first5); [1, 1, 2, 3, 5]
[0, 1, 1, 2, 3]
[0, 1, 2, 3, 5]
[1, 2, 3, 5, 8]