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

19 lines
462 B
JavaScript

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