From c1af2b0643e20e0a4ebf710887a85fe182820d1d Mon Sep 17 00:00:00 2001 From: Efrain Hernandez Date: Thu, 27 Aug 2020 22:05:20 -0500 Subject: [PATCH] =?UTF-8?q?Soluci=C3=B3n=20al=20reto=202=20de=20JavaScript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index c1c407d..e76dc1e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,28 @@ -const fibonacci = (n) => { - + const fibonacci = (n) => { + let arr = []; + if(n === 0) + return 0; + if(n === 1) { + arr.push(1) + return arr; + } + + + if(n === 2) { + arr.push(1,1) + return arr; + } + + if(n > 2) { + arr.push(1,1) + let fibonacciNumber = 0 + + for(let index = 1; index <= n-2; index++) { + fibonacciNumber = arr[index] + arr[index - 1] + arr.push(fibonacciNumber) + } + return arr; + } } - module.exports = fibonacci; \ No newline at end of file