diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..ecaf8c4 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,7 @@ const factorial = (number) => { // your code here + var fac=1; + for(var i=1;i<=number;i++){fac=fac*i; }return fac; } module.exports = factorial; \ No newline at end of file diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..05f2d8e 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,15 @@ const fibonacci = (n) => { // your code here + var fibo = []; + var a=0; + var b=1; +for (var i = 0; i < n; i++) { + var aux=a; + a=b; + b=aux+b; + fibo.push(a); +} +return fibo; } module.exports = fibonacci; \ No newline at end of file diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..5ce38b6 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,14 @@ const trialDivision = (number) => { // your code here + function isFloat(number){ + return Number(number) === number && number % 1 !== 0; +} + if (number == 0 || number == 1 || number == 4||number <= 1||isFloat(number)) return false; + for (let x = 2; x < number / 2; x++) { + if (number % x == 0) return false; + } + return true; + } module.exports = trialDivision; \ No newline at end of file