From ed36da6184f98ec73c4e7d9a75c1fb4891449ade Mon Sep 17 00:00:00 2001 From: genaroibc Date: Tue, 6 Sep 2022 10:02:42 -0300 Subject: [PATCH 1/3] [FEAT] add factorial function --- src/factorial.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..bb9f2bb 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,6 @@ -const factorial = (number) => { - // your code here -} +const factorial = number => { + if (number < 1) return 1; + return factorial(number - 1) * number; +}; -module.exports = factorial; \ No newline at end of file +module.exports = factorial; From ed14adc515c25980bfdc2123737ec98776c35658 Mon Sep 17 00:00:00 2001 From: genaroibc Date: Tue, 6 Sep 2022 10:42:04 -0300 Subject: [PATCH 2/3] [FEAT] add fibonacci function --- src/fibonacci.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..f21f6d5 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,18 @@ -const fibonacci = (n) => { - // your code here -} +const fibonacci = n => { + if (n < 1) return [0]; -module.exports = fibonacci; \ No newline at end of file + const resultsArr = [0, 1]; + let prev = 0; + let current = 1; + + while (current !== n) { + current = prev + current; + if (current > n) return resultsArr; + resultsArr.push(current); + prev = current - prev; + } + + return resultsArr; +}; + +module.exports = fibonacci; From d09dd6fbf9930af786f44d70874a655dcd5da8ea Mon Sep 17 00:00:00 2001 From: genaroibc Date: Mon, 12 Sep 2022 13:48:20 -0300 Subject: [PATCH 3/3] [FEAT] add trial division function --- src/primalidad.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..afaca28 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,14 @@ -const trialDivision = (number) => { - // your code here -} +const trialDivision = number => { + const factorsArr = []; + let factor = 2; -module.exports = trialDivision; \ No newline at end of file + while (number > 1) { + if (number % factor === 0) { + factorsArr.push(factor); + number /= factor; + } else factor += 1; + } + return factorsArr.length === 1; +}; + +module.exports = trialDivision;