Why does this Fibonacci number function return infinity for the 4000th value?

前端 未结 8 1377
攒了一身酷
攒了一身酷 2021-01-06 10:03
function fibo() {
var first,second,add;
for(var i=0;i<4000;i++){
    if(i === 0){
        first = 1;
        second = 2;
    }
    add = first + second;
    first         


        
8条回答
  •  时光说笑
    2021-01-06 10:23

    PubNub's Ariya Hidayat taught us this last night:

    function fibo(n) {
        return Array.apply(0, Array(n)). reduce(function(x, y, z){ return x.concat((z < 2) ? z : x[z-1] + x[z-2]); }, []);
         }
    

提交回复
热议问题