From a44507a99e67d842ee3a90b60844e98d5ebb1e41 Mon Sep 17 00:00:00 2001 From: Gaspar Pelayo Date: Tue, 6 Sep 2022 15:57:16 -0300 Subject: [PATCH 1/4] My resolution. --- src/factorial.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..4795454 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,9 @@ const factorial = (number) => { - // your code here + result = 1; + for(let i = number; i >= 1; i--){ + result *= number; + } + return result; } -module.exports = factorial; \ No newline at end of file +module.exports = factorial; From ae92991159ca4870ee146a9556478846f574be1b Mon Sep 17 00:00:00 2001 From: Gaspar Pelayo Date: Tue, 6 Sep 2022 16:44:55 -0300 Subject: [PATCH 2/4] My resolution. --- src/primalidad.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..10f4cbb 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,16 @@ -const trialDivision = (number) => { - // your code here -} +const trialDivision = + (number) => { + result = true; + if (number == 1) { + result = false; + } else { + for (let i = 2; i <= parseInt(Math.sqrt(number)); i++) { + if (number % i == 0) { + result = false; + } + } + } + return result; + } -module.exports = trialDivision; \ No newline at end of file +module.exports = trialDivision; From eb99fb49b89c8c97c1dbf6555c57127d28220152 Mon Sep 17 00:00:00 2001 From: Gaspar Pelayo Date: Tue, 6 Sep 2022 16:55:38 -0300 Subject: [PATCH 3/4] My resolution. --- src/fibonacci.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..977ee5c 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,9 @@ const fibonacci = (n) => { - // your code here + let listNumbers = [0, 1]; + for (let index = 2; index < n; index++) { + listNumbers.push(listNumbers[index - 1] + listNumbers[index-2]); + } + return listNumbers; } -module.exports = fibonacci; \ No newline at end of file +module.exports = fibonacci; From f88e9d456687f52e1294267e5c1640afda83f82b Mon Sep 17 00:00:00 2001 From: Gaspar Pelayo Date: Tue, 6 Sep 2022 17:10:07 -0300 Subject: [PATCH 4/4] My resolution. Correction of the before resolution. I did now make a function recursive. --- src/factorial.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/factorial.js b/src/factorial.js index 4795454..35cab6c 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,9 +1,9 @@ const factorial = (number) => { - result = 1; - for(let i = number; i >= 1; i--){ - result *= number; + if (number == 0) { + return 1; + } else { + return number * factorial(number - 1); } - return result; } module.exports = factorial;