From c6379b5b4e24d0e6d4248f53bc256fcfbe5b8fe2 Mon Sep 17 00:00:00 2001 From: Marcela Mathias Date: Wed, 2 Nov 2022 16:54:41 -0300 Subject: [PATCH] add fibonacci logic --- 04-fibonacci/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/04-fibonacci/index.js b/04-fibonacci/index.js index 37c64cc..7ef7188 100644 --- a/04-fibonacci/index.js +++ b/04-fibonacci/index.js @@ -1,4 +1,11 @@ export function fibonacci(value) { - // implementar logica aqui - -} \ No newline at end of file + if (value == 0) return 0; + let firstValue = 0; + let secondValue = 1; + for (let i = 2; i <= value; i++) { + let newValue = firstValue; + firstValue = secondValue; + secondValue += newValue; + } + return secondValue; +}