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

14 lines
336 B
JavaScript

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