From fc8adfc6f879bfa17381b323b95491e22ce0a575 Mon Sep 17 00:00:00 2001 From: Jose Prendiz Date: Fri, 9 Sep 2022 10:19:23 -0600 Subject: [PATCH] Reto cumplido --- src/factorial.js | 7 +++++++ src/fibonacci.js | 7 +++++++ src/primalidad.js | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..5c6e4fa 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,12 @@ const factorial = (number) => { // your code here + if (number === 0 || number === 1) { + return 1 + } + else { + 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..17b0a16 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,12 @@ const fibonacci = (n) => { // your code here + if (n === 0 || n === 1) { + return n + } + else { + return(fibonacci(n-1) * fibonacci(n - 2)) + } + } module.exports = fibonacci; \ No newline at end of file diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..341e90c 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,15 @@ const trialDivision = (number) => { // your code here + let flag = true + + for (i = 2; i < Math.trunc(number/2); i++) { + if (number % i === 0) { + flag = false + break; + } + } + + return flag } module.exports = trialDivision; \ No newline at end of file