From 4b743a1025b90ff136672aa10c3d64e929aa81de Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 6 Sep 2022 15:27:48 -0500 Subject: [PATCH] ejercicios realizados --- src/factorial.js | 2 ++ src/fibonacci.js | 10 ++++++++++ src/primalidad.js | 9 +++++++++ 3 files changed, 21 insertions(+) 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