refactor(desafio): Otimizacao da sequencia de fibonnaci

This commit is contained in:
Manuela Luana Schumacker Tavares 2022-10-31 14:19:47 -03:00
parent f1125c7604
commit 74da8d46ae

View File

@ -1,9 +1,19 @@
export function fibonacci(value) {
// implementar logica aqui
if(value < 2){
value = value;
}else{
value = fibonacci(value - 1) + fibonacci(value - 2);
if(value == 0){
return value;
}
return value;
let firstValue = 0, secondValue = 1, thirdValue =1;
for(let i = 2; i <= value; i++){
thirdValue = firstValue + secondValue;
firstValue = secondValue;
secondValue = thirdValue;
}
return thirdValue;
// if(value < 2){
// value = value;
// }else{
// value = fibonacci(value - 1) + fibonacci(value - 2);
// }
// return value;
}