function* fib() {
let [num1,num2] = [0,1];
for(;;){
yield num2;
[num1,num2]=[num2,num1+num2];
}
}
for(let num of fib()){
if(num>10000){break;}
console.log(num);
}
ES6生成器函数斐波那契数列
最新推荐文章于 2022-08-20 20:08:23 发布
function* fib() {
let [num1,num2] = [0,1];
for(;;){
yield num2;
[num1,num2]=[num2,num1+num2];
}
}
for(let num of fib()){
if(num>10000){break;}
console.log(num);
}