diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..96c8368 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,15 @@ export function fibonacci(value) { - // implementar logica aqui + let beforeLastNumber = 0; + let lastNumber = 1; + let nextNumber; + if (value < 2) return value; + + for (let i = 2; i <= value; i++) { + nextNumber = lastNumber + beforeLastNumber; + beforeLastNumber = lastNumber; + lastNumber = nextNumber; + } + + return lastNumber; } \ No newline at end of file