function getFibonacci(n){
var fibarr = [];
var i=0;
while(i<n){
if(i<=1){
fibarr.push(i);
}else{
fibarr.push(fibarr[i-1]+fibarr[i-2]);
}
i++;
}
return fibarr;
}
console.log(getFibonacci(6))
function getFibonacci(n){
var fibarr = [];
var i=0;
while(i<n){
if(i<=1){
fibarr.push(i);
}else{
fibarr.push(fibarr[i-1]+fibarr[i-2]);
}
i++;
}
return fibarr;
}
console.log(getFibonacci(6))
本文标题:5.斐波那契
本文链接:https://www.haomeiwen.com/subject/kvsjvxtx.html
网友评论