2022-10-27 15:07:13 +00:00
|
|
|
export function fibonacci(value) {
|
|
|
|
// implementar logica aqui
|
2022-10-28 19:02:42 +00:00
|
|
|
if(value < 1){
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if(value <= 2){
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
let prev = 0
|
|
|
|
let next = 1
|
|
|
|
let result = 0
|
2022-10-27 15:07:13 +00:00
|
|
|
|
2022-10-28 19:02:42 +00:00
|
|
|
for (let i = 2; i <= value; i++){
|
|
|
|
result = next + prev
|
|
|
|
prev = next
|
|
|
|
next = result
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|