From 9941c2a890c0b44facd711edbc1b2fa1f07ba370 Mon Sep 17 00:00:00 2001 From: Luiz Felipe Silva Date: Mon, 31 Oct 2022 22:20:35 -0300 Subject: [PATCH] feat(fibonacci): algoritmo criado. --- 04-fibonacci/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..838b39e 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,17 @@ export function fibonacci(value) { // implementar logica aqui - + if(value < 1) return 0; + if(value <= 2) return 1; + + let valorFib1 = 1; + let valorFib2 = 0; + let valorFibonacci = value; + + for(let i = 2; i <= value; i++) { + valorFibonacci = valorFib1 + valorFib2; + valorFib2 = valorFib1; + valorFib1 = valorFibonacci; + } + + return valorFibonacci; } \ No newline at end of file -- 2.34.1