12 lines
263 B
JavaScript
Raw Normal View History

export function fibonacci(value) {
2022-11-02 16:54:41 -03: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;
}