From bfc41a337c8cb9cb7045365d90b1126157223e1c Mon Sep 17 00:00:00 2001 From: francisco-solis99 Date: Wed, 7 Sep 2022 18:55:30 -0500 Subject: [PATCH] [Make] the challengues --- PULL_REQUEST_TEMPLATE.md | 11 ++++++----- package-lock.json | 6 +++--- src/factorial.js | 8 +++++++- src/fibonacci.js | 11 ++++++++++- src/primalidad.js | 7 ++++++- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 2449150..970c78f 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,11 @@ ## DESCRIPTION -Nombre: -Usuario Platzi: +Nombre: Francisco Javier Solis Martinez + +Usuario Platzi: FranciscoSolis ## Reto: -- [ ] Primer problema -- [ ] Segundo problema -- [ ] Tercer problema +- [✅] Primer problema +- [✅] Segundo problema +- [✅] Tercer problema diff --git a/package-lock.json b/package-lock.json index fd061e8..92817cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { - "name": "challenge-js-03", + "name": "javascript-challenges", "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "challenge-js-03", + "name": "javascript-challenges", "version": "1.0.0", "license": "MIT", "devDependencies": { - "jest": "^29.0.1" + "jest": "29.0.1" } }, "node_modules/@ampproject/remapping": { diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..26b362f 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,11 @@ const factorial = (number) => { // your code here + let factorial = 1; + while (number > 0) { + factorial *= number; + number -= 1; + } + return factorial; } -module.exports = factorial; \ No newline at end of file +module.exports = factorial; diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..df44583 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,14 @@ const fibonacci = (n) => { // your code here + const fiboList = []; + for (let i = 0; i < n; i += 1) { + if (i < 2) { + fiboList.push(1); + continue; + } + fiboList.push(fiboList[fiboList.length - 1] + fiboList[fiboList.length - 2]); + } + return fiboList; } -module.exports = fibonacci; \ No newline at end of file +module.exports = fibonacci; diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..67bdc4e 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,10 @@ const trialDivision = (number) => { // your code here + if (number < 2 || number % 1) return false; + for (let i = 2; i < number; i += 1) { + if (!(number % i)) return false; + } + return true; } -module.exports = trialDivision; \ No newline at end of file +module.exports = trialDivision;