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

13 lines
215 B
JavaScript

export function fibonacci(value) {
let previous = 0;
let sum = 0;
let next = 1;
for (let i = 0; i < value; i++) {
sum = previous + next;
previous = next;
next = sum;
}
return previous;
}