Advertisement
EntropyStarRover

Exercise with THIS: 02. Fibonacci with closure

Oct 31st, 2019
192
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function result() {
  2.     let f0 = 0;
  3.     let f1 = 1;
  4.  
  5.     return function () {
  6.         let oldf0 = f0;
  7.         console.log(oldf0);
  8.         let oldf1 = f1;
  9.         console.log(oldf1)
  10.  
  11.         f0 = oldf1;
  12.         f1 = oldf0 + oldf1;
  13.  
  14.         return f0;
  15.     }
  16.  
  17. }
  18.  
  19. let fib = result();
  20. fib();
  21. fib();
  22. fib();
Advertisement
RAW Paste Data Copied
Advertisement