diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..35cab6c 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,9 @@ const factorial = (number) => { - // your code here + if (number == 0) { + return 1; + } else { + return number * factorial(number - 1); + } } -module.exports = factorial; \ No newline at end of file +module.exports = factorial; diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..977ee5c 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,9 @@ const fibonacci = (n) => { - // your code here + let listNumbers = [0, 1]; + for (let index = 2; index < n; index++) { + listNumbers.push(listNumbers[index - 1] + listNumbers[index-2]); + } + return listNumbers; } -module.exports = fibonacci; \ No newline at end of file +module.exports = fibonacci; diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..10f4cbb 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,16 @@ -const trialDivision = (number) => { - // your code here -} +const trialDivision = + (number) => { + result = true; + if (number == 1) { + result = false; + } else { + for (let i = 2; i <= parseInt(Math.sqrt(number)); i++) { + if (number % i == 0) { + result = false; + } + } + } + return result; + } -module.exports = trialDivision; \ No newline at end of file +module.exports = trialDivision;