| Total Complexity | 5 |
| Complexity/F | 1.67 |
| Lines of Code | 20 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | const memoize = (fn) => { |
||
| 2 | let cache = {}; |
||
| 3 | return (...args) => { |
||
| 4 | if (cache[args]) { |
||
| 5 | return cache[args]; |
||
| 6 | } |
||
| 7 | const result = fn.apply(this, args); |
||
| 8 | cache[args] = result; |
||
| 9 | return result; |
||
| 10 | } |
||
| 11 | } |
||
| 12 | let fib = num => { |
||
| 13 | // put your code here to address problems |
||
| 14 | if (num < 2) { |
||
| 15 | return num; |
||
| 16 | } |
||
| 17 | return fib(num - 1) + fib(num - 2); |
||
| 18 | } |
||
| 19 | fib = memoize(fib); |
||
| 20 | module.exports = fib; |