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