From a0e3f1c4a5848eaf68c3275a7669192cd08cec17 Mon Sep 17 00:00:00 2001 From: Nicolas Oliveira <110689312+thedevnicolas@users.noreply.github.com> Date: Fri, 28 Oct 2022 10:25:39 -0300 Subject: [PATCH] feat(desafio04):desafio-completo --- 04-fibonacci/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..c111ec9 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 fibMinus2 = 0 + let fibMinus1 = 1 + let fibN = value + for (let i = 2; i <=value; i++){ + fibN = fibMinus1 + fibMinus2 + fibMinus2 = fibMinus1 + fibMinus1 = fibN + } + return fibN } \ No newline at end of file