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

17 lines
294 B
JavaScript
Raw Normal View History

export function fibonacci(value) {
2022-10-28 23:17:52 +00:00
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
}