From 016dbfb2014c483687b7424764817127f39be5e0 Mon Sep 17 00:00:00 2001 From: Felipe Huerta Aros Date: Tue, 6 Sep 2022 23:52:54 -0400 Subject: [PATCH] =?UTF-8?q?Soluci=C3=B3n=20al=20Reto=20del=20Near=20Develo?= =?UTF-8?q?per=20Program=20=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PULL_REQUEST_TEMPLATE.md | 10 +++++----- package-lock.json | 6 +++--- src/factorial.js | 10 +++++++--- src/fibonacci.js | 15 ++++++++++++--- src/primalidad.js | 17 ++++++++++++++--- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 2449150..77e5b0c 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,10 @@ ## DESCRIPTION -Nombre: -Usuario Platzi: +Nombre: Felipe Huerta Aros +Usuario Platzi: hueeerta ## Reto: -- [ ] Primer problema -- [ ] Segundo problema -- [ ] Tercer problema +- [x] Primer problema +- [x] Segundo problema +- [x] 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..ff67fbf 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,9 @@ const factorial = (number) => { - // your code here -} + var resultado = 1; + for (let index = resultado; index <= number; index++) { + resultado = resultado * index; + } + return resultado; +}; -module.exports = factorial; \ No newline at end of file +module.exports = factorial; diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..619cd14 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,14 @@ const fibonacci = (n) => { - // your code here -} + var secuenciaFibo = [1]; + for (let index = 0; index < n; index++) { + if (secuenciaFibo.length < 2) { + secuenciaFibo[index] = 1; + } else if (secuenciaFibo.length >= 2) { + secuenciaFibo[index] = + secuenciaFibo[index - 1] + secuenciaFibo[index - 2]; + } + } + return secuenciaFibo; +}; -module.exports = fibonacci; \ No newline at end of file +module.exports = fibonacci; diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..68cb10a 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,16 @@ const trialDivision = (number) => { - // your code here -} + var tipoCompuesto = 0; + var tipoPrimo = 0; + for (let index = 1; index <= number; index++) { + if (Number.isInteger(number / index)) { + tipoCompuesto++; + } else { + tipoPrimo++; + } + } + tipoCompuesto -= 2; + return tipoCompuesto == 0 ? true : false; + // console.log("Compuesto: " + tipoCompuesto + " - Primo: " + tipoPrimo); +}; -module.exports = trialDivision; \ No newline at end of file +module.exports = trialDivision;