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

18 lines
349 B
JavaScript

export function fibonacci(value) {
// implementar logica aqui
if (value < 1) {
return 0;
} else if (value <= 2) {
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;
}
}