📜  如何在 javascript 代码示例中生成斐波那契数列

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

代码示例3
// number fibonnaci to array format
function fibonacci(nums) {
  
  let fib = [0, 1];
  let data = [];
  
  for(let i = 2; i <= nums; i++) {
    fib[i] = fib[i - 1] + fib[i - 2]; 
    data.push(fib[i]);
  }
  
  return data;
}