Skip to content

2803. Factorial Generator 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function* factorial(n: number): Generator<number> {
  if (n === 0) {
    yield 1;
  }
  let fact = 1;
  for (let i = 1; i <= n; ++i) {
    fact *= i;
    yield fact;
  }
}