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