Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let memo = [];
  2.  
  3. function fib(n) {
  4.     if (n === 1) {
  5.         return 1;
  6.     } else if (n === 0) {
  7.         return 0;
  8.     }
  9.  
  10.     if (memo[n] !== undefined) {
  11.         return memo[n];
  12.     }
  13.  
  14.     let result = fib(n - 1) + fib(n - 2);
  15.     memo[n] = result;
  16.  
  17.     return result;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement