From dbbbb6c4c6a0da5448536997d88fdfd6309044d7 Mon Sep 17 00:00:00 2001 From: HenriqueSSan Date: Thu, 27 Oct 2022 20:51:29 -0300 Subject: [PATCH] feat(challenge-4): completed challenge --- 04-fibonacci/index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..ef73b48 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,16 @@ export function fibonacci(value) { // implementar logica aqui - -} \ No newline at end of file + if (!value) return 0; + + let n1 = 0, + n2 = 1, + nextTerm; + + for (let i = 1; i <= value; i++) { + nextTerm = n1 + n2; + n1 = n2; + n2 = nextTerm; + } + + return n1; +}