From f565336c05aed1c037ad2282b0acc90a7797d293 Mon Sep 17 00:00:00 2001 From: Maricela Chavarria Date: Fri, 17 Mar 2023 00:04:27 -0400 Subject: [PATCH] challenge completed --- package-lock.json | 6 +++--- src/factorial.js | 7 +++++-- src/fibonacci.js | 15 +++++++++++++-- src/primalidad.js | 12 +++++++++++- 4 files changed, 32 insertions(+), 8 deletions(-) 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..01236ad 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,8 @@ -const factorial = (number) => { - // your code here +const factorial = (n) => { + if (n==0 | n==1) + return 1 + else + return n * (factorial(n-1)) } module.exports = factorial; \ No newline at end of file diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..7410dc2 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,16 @@ -const fibonacci = (n) => { - // your code here +const secuenciaFibo = (n) => { + if (n <= 1) + return n + else + return parseInt(secuenciaFibo(n-1))+parseInt(secuenciaFibo(n-2)) +} + +const fibonacci = (n) =>{ + let fibo = [] + for(let i=1; i<=n; i++){ + fibo.push(secuenciaFibo(i)) + } + return fibo } module.exports = fibonacci; \ No newline at end of file diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..8d64089 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,15 @@ const trialDivision = (number) => { - // your code here + if(number>1 && Number.isInteger(number)){ + for(let i=2; i