📜  javascript中使用for循环的斐波那契序列 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:28.487000             🧑  作者: Mango

代码示例1
let fibonacci = [0, 1]; // set initial conditions

for (let i = 2; i < 10; ++i) {
    // add the two previous elements to get the current element
    fibonacci[i] = fibonacci[i - 2] + fibonacci[i - 1];
}

console.log(fibonacci); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]