summaryrefslogtreecommitdiff
path: root/graphs/js/eslint/fibo.js
blob: 9b466e7acdd46e122e01a4c1f8707ab86a579ecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function fibo(n) {
    // I'm a comment
    if (typeof n != "number" || isNaN(n)) {
        return -1;
    }

    if (n < 0) {
        return -1;
    }

    if (n === 0) {
        return 0;
    }

    let a = 1;

    let b = 1;
    let result = 1;

    for (let i = 2; i < n; i++) {
        result = a + b;
        b = a;
        a = result;
    }

    return result;
}

module.exports = {
    fibo,
};