22 lines
306 B
JavaScript
22 lines
306 B
JavaScript
export function fibonacci(value) {
|
|
// implementar logica aqui
|
|
if(value < 1){
|
|
return 0
|
|
}
|
|
|
|
if(value <= 2){
|
|
return 1
|
|
}
|
|
|
|
let prev = 0
|
|
let next = 1
|
|
let result = 0
|
|
|
|
for (let i = 2; i <= value; i++){
|
|
result = next + prev
|
|
prev = next
|
|
next = result
|
|
}
|
|
|
|
return result
|
|
} |