diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 2449150..7272bea 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,9 +1,9 @@ ## DESCRIPTION Nombre: -Usuario Platzi: +Usuario -## Reto: +## Reto - [ ] Primer problema - [ ] Segundo 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..159786d 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,16 @@ const factorial = (number) => { - // your code here + + if(number === 0){ + return 1; + } + + for(let i = number - 1; i > 0; i--){ + number *= i + } + + return number + + } module.exports = factorial; \ No newline at end of file diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..c346722 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,17 @@ const fibonacci = (n) => { - // your code here + let array = [0,1] + + if(n < 2){ + return [n] + } + + for(let i = 1; i < n; i++){ + array.push(array[i] + array[i - 1]) + } + + array.shift() + + return array } module.exports = fibonacci; \ No newline at end of file diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..139ea9f 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,17 @@ const trialDivision = (number) => { - // your code here + + if (number <= 1 || !Number.isInteger(number)){ + return false + } + + for(let i = number - 1; i > 1; i--){ + if(number % i === 0){ + return false + } + } + + return true + } module.exports = trialDivision; \ No newline at end of file