diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..cac3c65 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,21 @@ export function fibonacci(value) { // implementar logica aqui - -} \ No newline at end of file + if (value < 1) return 0 + if (value <= 2) return 1 + let result = 0 + let result2 = 1 + let resultado = value + for ( let i =2; i <=value; i++){ + resultado = result2 + result + result = result2 + result2 =resultado + } + return resultado +} +console.log(fibonacci(0)) +console.log(fibonacci(1)) +console.log(fibonacci(2)) +console.log(fibonacci(3)) +console.log(fibonacci(4)) +console.log(fibonacci(5)) +console.log(fibonacci(6)) \ No newline at end of file