diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 2449150..542454b 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,10 @@ ## DESCRIPTION -Nombre: -Usuario Platzi: +Nombre: nahum +Usuario Platzi: nahum_1_121@hotmail.com ## 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..0234c53 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,12 @@ const factorial = (number) => { - // your code here + var result = number; + if (number === 0 || number === 1) + return 1; + while (number > 1) { + number--; + result *= number; + } + return result; } module.exports = factorial; \ No newline at end of file diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..2323637 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,22 @@ const fibonacci = (n) => { - // your code here + + if (!n) return; + + var fibArr = [1]; + + if (n === 1) { + console.log(fibArr); + return fibArr; + } + + fibArr.push(1); + + for(var i = 2, len = n; i < len; i++) { + fibArr.push(fibArr[i-1] + fibArr[i-2]); + } + console.log(fibArr); + return fibArr; + } module.exports = fibonacci; \ No newline at end of file diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..1a7a6b5 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,25 @@ const trialDivision = (number) => { - // your code here + if(number % 1 == 0){ + for (var i = 2; i < number; i++) { + if (number % i === 0) { + console.log(false); + return false; + } + + } + + if (number === 1 || number === -1 || number === 0) { + console.log(false); + return false; + } else { + console.log(true); + return true; + } + }else{ + console.log(false); + return false; + } + } module.exports = trialDivision; \ No newline at end of file