Skip to content

2648. Generate Fibonacci Sequence 👍

1
2
3
4
5
6
7
8
9
function* fibGenerator(): Generator<number, any, number> {
  const arr = [0, 0, 1];
  while (true) {
    yield arr[1];
    arr[0] = arr[1];
    arr[1] = arr[2];
    arr[2] = arr[0] + arr[1];
  }
}