1 Star 0 Fork 2

原罪/javascript-algorithms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
fibonacci.js 496 Bytes
一键复制 编辑 原始数据 按行查看 历史
Oleksii Trekhleb 提交于 2018-06-14 12:59 +08:00 . Code style fixes.
/**
* Return a fibonacci sequence as an array.
*
* @param n
* @return {number[]}
*/
export default function fibonacci(n) {
const fibSequence = [1];
let currentValue = 1;
let previousValue = 0;
if (n === 1) {
return fibSequence;
}
let iterationsCounter = n - 1;
while (iterationsCounter) {
currentValue += previousValue;
previousValue = currentValue - previousValue;
fibSequence.push(currentValue);
iterationsCounter -= 1;
}
return fibSequence;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wzhgitee/javascript-algorithms.git
git@gitee.com:wzhgitee/javascript-algorithms.git
wzhgitee
javascript-algorithms
javascript-algorithms
master

搜索帮助