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..9c7f5e2 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,7 @@ const factorial = (number) => { // your code here + const result = (n) => n == 0 ? 1 : n*result(n-1); + return result(number); } module.exports = factorial; \ No newline at end of file diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..61c2624 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,14 @@ -const fibonacci = (n) => { +const fibonacci = (number) => { // your code here + const result=(n)=>{ + if(n<=1)return [1,1]; + + let r = result(n-1); + r.push(r[r.length - 1] + r[r.length - 2]); + return r; + } + return number==1?[1]:result(number-1) } + module.exports = fibonacci; \ No newline at end of file diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..0cf69b6 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,10 @@ const trialDivision = (number) => { // your code here + if(Math.floor(number)-number)return false + for(let i=2;i<=Math.sqrt(number);i++){ + if(number%i===0) return false; + } + return number>1; } module.exports = trialDivision; \ No newline at end of file