refactor: funcao fibonacci

This commit is contained in:
Caio Thurler 2022-10-31 14:39:52 -03:00
parent 293b56673c
commit 29ae11b58c

View File

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