2022-10-27 15:07:13 +00:00
|
|
|
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
|
2022-10-27 15:07:13 +00:00
|
|
|
}
|