refactor: funcao fibonacci
This commit is contained in:
parent
293b56673c
commit
29ae11b58c
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user