Custom/Modified 'Fibonacci' Number sequence

UPDATE:

Try following one.
Parameters: n from where to start saving numbers, m how many numbers do you want to save

function getFibonacci(n,m) {
    var a = 0, b = 1, z = null, arr = [], c = 0;

    for ( var i = 0; i <= n; i++ ) {
        if ( a >= n ) {
            if ( c >= m ) {
                return arr;
            }
            arr.push(a);
            c++;
        }
        z = a + b;
        a = b;
        b = z;
    }
}

getFibonacci(60000000,10); // [63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976]

DEMO

Leave a Comment