求出斐波那契数组

function fib(max) {
    let t,
        a = 0,
        b = 1,
        arr = [a, b];
    while (arr.length < max) {
        [a, b] = [b, a + b];
        arr.push(b);
    }
    return arr;
}
fib(5);

结果:
[0, 1, 1, 2, 3]

 

posted @ 2018-09-07 10:42  刘倩文  阅读(82)  评论(0编辑  收藏  举报