From c6ca6f99f0b3fdc9aea33d1cc4f43806faa66ad6 Mon Sep 17 00:00:00 2001 From: Savio Date: Sun, 30 Oct 2022 14:44:32 -0300 Subject: [PATCH] feat(fibonacci): Adicionando algoritmo que retorna o resultado da sequencia de fibonacci. --- 04-fibonacci/index.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..e5ccd64 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,15 @@ export function fibonacci(value) { - // implementar logica aqui - -} \ No newline at end of file + let vet = []; + vet.push(0); + vet.push(1); + if (value == 0) { + return vet[0]; + } else if (value == 1) { + return vet[1]; + } else { + for (let index = 2; index <= value; index++) { + vet[index] = vet[index - 2] + vet[index - 1]; + } + } + return vet.at(-1); +} -- 2.34.1