diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 2449150..604d46a 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -1,7 +1,7 @@ ## DESCRIPTION -Nombre: -Usuario Platzi: +Nombre: Luis Miguel Osorio Marin +Usuario Platzi: Miguel Osorio miguelosorio613@gmail.com ## Reto: diff --git a/src/factorial.js b/src/factorial.js index 4f3ae70..05a0232 100644 --- a/src/factorial.js +++ b/src/factorial.js @@ -1,5 +1,16 @@ const factorial = (number) => { // your code here + function factorial (num){ + if(num <= 0){ + console.log("Lo sentimos, el numero debe ser mayor que cero"); + }else{ + let factorial = num; + for(let i = (num - 1); i > 1; i--){ + factorial *= i; + } + return `El factorial de ${num} es: ${factorial}` + } +} } -module.exports = factorial; \ No newline at end of file +module.exports = factorial; diff --git a/src/fibonacci.js b/src/fibonacci.js index ea3270f..a0da9cb 100644 --- a/src/fibonacci.js +++ b/src/fibonacci.js @@ -1,5 +1,22 @@ const fibonacci = (n) => { // your code here + function fibonacci(num){ + // El parametro indica la cantidad de numeros que se quieren obtener de la secuencia + let partida = 0; + let inicial = 1; + let array = []; + + if(num <= 0){ + console.log("Lo sentimos, el numero debe ser mayor que uno"); + }else{ + for(let i = 0; i < num; i++){ + array.push(partida); + partida += inicial; + inicial = array[i]; + } + } + return array; +} } -module.exports = fibonacci; \ No newline at end of file +module.exports = fibonacci; diff --git a/src/primalidad.js b/src/primalidad.js index 8bdb849..04a79b0 100644 --- a/src/primalidad.js +++ b/src/primalidad.js @@ -1,5 +1,29 @@ const trialDivision = (number) => { // your code here + function primo (num){ + let contador = 0; + let valor; + let mensaje; + if(num <= 1){ + mensaje = "Lo sentimos, el numero debe ser mayor que uno"; + }else{ + for(let i = num; i > 1; i--){ + for(let j = 1; j <= num; j++){ + valor = i * j; + if(valor == num){ + contador++; + } + } + } + if(contador <= 2){ + mensaje = `El numero ${num} es primo` + }else{ + mensaje = `El numero ${num} no es primo` + } + } + + return mensaje; +} } -module.exports = trialDivision; \ No newline at end of file +module.exports = trialDivision;