2022-10-27 15:07:13 +00:00
|
|
|
export function fibonacci(value) {
|
|
|
|
// implementar logica aqui
|
2022-10-28 12:51:31 +00:00
|
|
|
let penultimo = 0,
|
2022-10-28 12:50:15 +00:00
|
|
|
ultimo = 1;
|
2022-10-28 12:51:31 +00:00
|
|
|
let numero;
|
2022-10-28 12:50:15 +00:00
|
|
|
let arr = [];
|
|
|
|
if (value < 2) {
|
2022-10-28 11:40:50 +00:00
|
|
|
return value;
|
2022-10-28 12:50:15 +00:00
|
|
|
} else {
|
2022-10-28 12:51:31 +00:00
|
|
|
for (let count = 2; count <= value; count++) {
|
2022-10-28 12:50:15 +00:00
|
|
|
numero = ultimo + penultimo;
|
|
|
|
penultimo = ultimo;
|
|
|
|
ultimo = numero;
|
|
|
|
arr.push(ultimo);
|
|
|
|
}
|
|
|
|
return arr[value - 2];
|
2022-10-28 11:40:50 +00:00
|
|
|
}
|
|
|
|
}
|