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

19 lines
377 B
JavaScript
Raw Permalink Normal View History

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
}
}