forked from M3-Academy/challenge-algorithms-v2.0
12 lines
263 B
JavaScript
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;
|
|
}
|