diff --git a/README.md b/README.md index 0242224..9f6ee24 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,9 @@ npm run test 15 = 1 307 674 368 000. ``` -1. Genera un algoritmo para determinar si un número de entrada es primo o no. -2. Genera una función que devuelve una secuencia de Fibonacci como una array +2. Genera un algoritmo para determinar si un número de entrada es primo o no. + +3. Genera una función que devuelve una secuencia de Fibonacci como una array ### Enviar solución de reto diff --git a/package-lock.json b/package-lock.json index fd061e8..7f732fb 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": { @@ -5144,8 +5144,7 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.2.tgz", "integrity": "sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==", - "dev": true, - "requires": {} + "dev": true }, "jest-regex-util": { "version": "29.0.0", diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..7052668 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,6 @@ const factorial = (number) => { - // your code here + if (number == 0 || number == 1) return 1; + return number * factorial (number-1); } module.exports = factorial; \ No newline at end of file diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..9c6c3b9 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,10 @@ const fibonacci = (n) => { - // your code here + if (n == 0) return [0]; + if (n == 1) return [1]; + if (n == 2) return [1, 1]; + let fibonacciArray = fibonacci(n - 1); + fibonacciArray.push(fibonacciArray[n - 2] + fibonacciArray[n - 3]); + return fibonacciArray; } module.exports = fibonacci; \ No newline at end of file diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..440a086 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,8 @@ -const trialDivision = (number) => { - // your code here +const trialDivision = (number) => { + if (number % 1 !== 0) return false; + for (let i = 2; i < number; i++) + if (number % i === 0) return false; + return number >= 2; } module.exports = trialDivision; \ No newline at end of file