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

17 lines
342 B
JavaScript
Raw Permalink Normal View History

export function fibonacci(value) {
// implementar logica aqui
let number1 = 0;
let number2 = 1;
let result;
if (value === 0 || value === 1 ) {
return value;
} else {
for (let i = 1 ; i < value ; i++) {
result = number2 + number1;
number1 = number2;
number2 = result;
}
}
return result;
}