Advertisement
Diriector_Doc

Fibonacci class JavaScript

Apr 16th, 2021
1,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class fib {
  2.     constructor() {
  3.         this.a = (function*() {
  4.             let a = 0,
  5.                 b = 1;
  6.             yield 0;
  7.             while (true) {
  8.                 let t = a + b;
  9.                 a = b;
  10.                 yield b = t
  11.             }
  12.         })()
  13.     }
  14.     get next() {
  15.         return this.a.next().value;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement