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

17 lines
294 B
JavaScript

export function fibonacci(value) {
if (value < 1) return 0
if (value <= 2) return 1
let fibonnaci1 = 0
let fibonnaci2 = 1
let fibx = value
for (let i = 2; i <= value; i++) {
fibx = fibonnaci2 + fibonnaci1
fibonnaci1 = fibonnaci2
fibonnaci2 = fibx
}
return fibx
}