fork download
  1. function* fibonacciGenerator() {
  2. let a = 0,
  3. b = 1;
  4. while (true) {
  5. yield a;
  6. [a, b] = [b, a + b];
  7. }
  8. }
  9.  
  10. const genFib = fibonacciGenerator();
  11.  
  12. console.log(genFib.next().value);
  13. console.log(genFib.next().value);
  14. console.log(genFib.next().value);
  15. console.log(genFib.next().value);
  16. console.log(genFib.next().value);
  17.  
Success #stdin #stdout 0.08s 31660KB
stdin
Standard input is empty
stdout
0
1
1
2
3