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

17 lines
243 B
JavaScript
Raw Normal View History

export function fibonacci(value) {
// implementar logica aqui
2022-10-27 23:51:29 +00:00
if (!value) return 0;
let n1 = 0,
n2 = 1,
nextTerm;
for (let i = 1; i <= value; i++) {
nextTerm = n1 + n2;
n1 = n2;
n2 = nextTerm;
}
return n1;
}