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

14 lines
386 B
JavaScript

export function fibonacci(value) {
// implementar logica aqui
if (value < 1) return 0
if (value <= 2) return 1
let fib1 = 0
let fib2 = 1
let fibN = value
for (let i = 2; i <=value; i++){
fibN = fib2 + fib1
fib1 = fib2
fib2 = fibN
}
return fibN
}