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

14 lines
336 B
JavaScript
Raw Normal View History

export function fibonacci(value) {
// implementar logica aqui
2022-10-31 15:45:34 +00:00
if (value < 1) return 0
if (value <= 2) return 1
2022-10-31 15:45:41 +00:00
let fibAnterior = 0
let fibProximo = 1
let fibValue = value
2022-10-31 15:45:34 +00:00
for(let i = 2; i <= value; i++){
2022-10-31 15:45:41 +00:00
fibValue = fibProximo + fibAnterior
fibAnterior = fibProximo
fibProximo = fibValue
2022-10-31 15:45:34 +00:00
}
2022-10-31 15:45:41 +00:00
return fibValue
}