From aaed0ee98d5a0967843f262675a32fede40fbaa8 Mon Sep 17 00:00:00 2001 From: Ramon Dias Ferreira Date: Sat, 29 Oct 2022 18:09:07 -0300 Subject: [PATCH] =?UTF-8?q?feat(fibonacci):=20condi=C3=A7=C3=B5es=20e=20lo?= =?UTF-8?q?op=20utilizados=20na=20resolu=C3=A7=C3=A3o,=20funcional=20em=20?= =?UTF-8?q?todos=20os=20testes.=20Comentario=20com=20primeira=20logica,=20?= =?UTF-8?q?mas=20estava=20mal=20otimizada.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04-fibonacci/index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..73e275e 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,25 @@ export function fibonacci(value) { // implementar logica aqui - + if(value < 1) return 0 + if(value <=2) return 1 + let fibMin2 = 0 + let fibMin1 = 1 + let fibValue = value + for(let i = 2; i <= value; i++) { + fibValue = fibMin1 + fibMin2 + fibMin2 = fibMin1 + fibMin1 = fibValue + } + return fibValue + +// Forma inicial pensada, mas demorava muito tempo para passar nos testes. + + // if(value === 0) { + // return 0 + // } + // else if (value <= 2) { + // return 1 + // } + // return fibonacci(value - 1) + fibonacci(value - 2); + } \ No newline at end of file