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

13 lines
215 B
JavaScript
Raw Normal View History

export function fibonacci(value) {
2022-10-28 22:21:13 +00:00
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;
}