topics/fib/index.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 20
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
mnd 2
bc 2
fnc 3
dl 0
loc 20
rs 10
bpm 0.6666
cpm 1.6666
noi 0
c 0
b 0
f 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;