challenge-algorithms-v2.0-m.../04-fibonacci/index.js

12 lines
263 B
JavaScript
Raw Permalink Normal View History

export function fibonacci(value) {
2022-11-02 19:54:41 +00:00
if (value == 0) return 0;
let firstValue = 0;
let secondValue = 1;
for (let i = 2; i <= value; i++) {
let newValue = firstValue;
firstValue = secondValue;
secondValue += newValue;
}
return secondValue;
}