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

18 lines
349 B
JavaScript
Raw Permalink Normal View History

export function fibonacci(value) {
// implementar logica aqui
2022-10-31 17:39:52 +00:00
if (value < 1) {
return 0;
} else if (value <= 2) {
2022-10-31 17:39:52 +00:00
return 1;
} else {
let previous = 0;
let next = 1;
let total;
for (let i = 2; i <= value; i++) {
total = next + previous;
previous = next;
next = total;
}
return total;
}
2022-10-30 12:27:58 +00:00
}