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

12 lines
263 B
JavaScript

export function fibonacci(value) {
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;
}