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

13 lines
248 B
JavaScript

export function fibonacci(value) {
let add = 0
let previousValue = 0
let nextValue = 1
for (let i = 0; i < value; i++) {
add = previousValue + nextValue;
previousValue = nextValue;
nextValue = add;
}
return previousValue
}