diff --git a/C5 Fundamentos Javascript/ejercicios/01.js b/C5 Fundamentos Javascript/ejercicios/01.js index 62feaaf6f6..ddd8ed4c09 100644 --- a/C5 Fundamentos Javascript/ejercicios/01.js +++ b/C5 Fundamentos Javascript/ejercicios/01.js @@ -1,6 +1,6 @@ // Crea una variable de tipo string. // Reemplaza el valor de null por el correspondiente. -const nuevoString = null; +const nuevoString = "null"; module.exports = nuevoString; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/02.js b/C5 Fundamentos Javascript/ejercicios/02.js index d4f06a1b48..3dc5940fac 100644 --- a/C5 Fundamentos Javascript/ejercicios/02.js +++ b/C5 Fundamentos Javascript/ejercicios/02.js @@ -1,6 +1,6 @@ // Crea una variable de tipo number. // Reemplaza el valor de null por el correspondiente. -const nuevoNumero = null; +const nuevoNumero = 1; module.exports = nuevoNumero; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/03.js b/C5 Fundamentos Javascript/ejercicios/03.js index 189ca4b52d..f2f01ede6f 100644 --- a/C5 Fundamentos Javascript/ejercicios/03.js +++ b/C5 Fundamentos Javascript/ejercicios/03.js @@ -1,6 +1,6 @@ // Crea una variable de tipo boolean. // Reemplaza el valor de null por el correspondiente. -const nuevoBoolean = null; +const nuevoBoolean = true; module.exports = nuevoBoolean; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/04.js b/C5 Fundamentos Javascript/ejercicios/04.js index fff0fb6335..a52adb07c2 100644 --- a/C5 Fundamentos Javascript/ejercicios/04.js +++ b/C5 Fundamentos Javascript/ejercicios/04.js @@ -1,6 +1,6 @@ // Resuelve el siguiente problema matemático. // Reemplaza el valor de null por el correspondiente. -const nuevaResta = 10 - null === 3; +const nuevaResta = 10 - 7 === 3; module.exports = nuevaResta; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/05.js b/C5 Fundamentos Javascript/ejercicios/05.js index 82e2dac5fe..0dabb9307d 100644 --- a/C5 Fundamentos Javascript/ejercicios/05.js +++ b/C5 Fundamentos Javascript/ejercicios/05.js @@ -1,6 +1,6 @@ // Resuelve el siguiente problema matemático. // Reemplaza el valor de null por el correspondiente. -const nuevaMultiplicacion = 10 * null === 40; +const nuevaMultiplicacion = 10 * 4 === 40; module.exports = nuevaMultiplicacion; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/06.js b/C5 Fundamentos Javascript/ejercicios/06.js index 6debf25fc4..4fa4e9c7de 100644 --- a/C5 Fundamentos Javascript/ejercicios/06.js +++ b/C5 Fundamentos Javascript/ejercicios/06.js @@ -1,6 +1,6 @@ // Resuelve el siguiente problema matemático. // Reemplaza el valor de null por el correspondiente. -const nuevoModulo = 21 % 5 === null; +const nuevoModulo = 21 % 5 === 1; module.exports = nuevoModulo; diff --git a/C5 Fundamentos Javascript/ejercicios/07.js b/C5 Fundamentos Javascript/ejercicios/07.js index 8eecae1d84..e66f58160f 100644 --- a/C5 Fundamentos Javascript/ejercicios/07.js +++ b/C5 Fundamentos Javascript/ejercicios/07.js @@ -3,6 +3,8 @@ function esTipoDato(valor) { // Retorna el tipo de dato de este valor. // Por ejemplo: "string", "number", "boolean", "object", etc. // Tu código: + let tipoValor = typeof valor + return tipoValor } module.exports = esTipoDato; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/08.js b/C5 Fundamentos Javascript/ejercicios/08.js index b6594f3466..faeedbbdd6 100644 --- a/C5 Fundamentos Javascript/ejercicios/08.js +++ b/C5 Fundamentos Javascript/ejercicios/08.js @@ -7,6 +7,11 @@ function esNumeroEntero(numero) { // -1212 ---> true // 121.212 ---> false // Tu código: + if (Number.isInteger(numero)){ + return true + } else { + return false + } } module.exports = esNumeroEntero; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/09.js b/C5 Fundamentos Javascript/ejercicios/09.js index 665d437709..aca2db7408 100644 --- a/C5 Fundamentos Javascript/ejercicios/09.js +++ b/C5 Fundamentos Javascript/ejercicios/09.js @@ -8,6 +8,11 @@ function esNuloOIndefinido(valor) { // 22 ---> false // "texto" ---> false // Tu código: + if (valor === null || valor === undefined){ + return true + }else{ + return false + } } module.exports = esNuloOIndefinido; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/10.js b/C5 Fundamentos Javascript/ejercicios/10.js index a2f730da93..b9ea975f69 100644 --- a/C5 Fundamentos Javascript/ejercicios/10.js +++ b/C5 Fundamentos Javascript/ejercicios/10.js @@ -6,6 +6,7 @@ function devolverString(string) { // "hola mundo" ---> "hola mundo" // "SoyHenry" ---> "SoyHenry" // Tu código: + return string; } module.exports = devolverString; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/11.js b/C5 Fundamentos Javascript/ejercicios/11.js index 2a4d40a899..6fec931c7c 100644 --- a/C5 Fundamentos Javascript/ejercicios/11.js +++ b/C5 Fundamentos Javascript/ejercicios/11.js @@ -6,6 +6,11 @@ function sonIguales(x, y) { // 5, 5 ---> true // 5, 8 ---> false // Tu código: + if (x === y) { + return true + } else{ + return false + } } module.exports = sonIguales; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/12.js b/C5 Fundamentos Javascript/ejercicios/12.js index bce832204b..f3167537df 100644 --- a/C5 Fundamentos Javascript/ejercicios/12.js +++ b/C5 Fundamentos Javascript/ejercicios/12.js @@ -6,6 +6,11 @@ function tienenMismaLongitud(str1, str2) { // "SoyHenry", "HenrySoy" ---> true // "hi", "there" ---> false // Tu código: + if (str1.length == str2.length){ + return true + } else { + return false + } } module.exports = tienenMismaLongitud; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/13.js b/C5 Fundamentos Javascript/ejercicios/13.js index 5e4d000dd4..12c24c79a1 100644 --- a/C5 Fundamentos Javascript/ejercicios/13.js +++ b/C5 Fundamentos Javascript/ejercicios/13.js @@ -6,6 +6,11 @@ function menosQueNoventa(num) { // 50 ---> true // 91 ---> false // Tu código: + if (num < 90){ + return true + } else{ + return false + } } module.exports = menosQueNoventa; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/14.js b/C5 Fundamentos Javascript/ejercicios/14.js index cd5d24fbd1..9e935ca988 100644 --- a/C5 Fundamentos Javascript/ejercicios/14.js +++ b/C5 Fundamentos Javascript/ejercicios/14.js @@ -6,6 +6,12 @@ function mayorQueCincuenta(num) { // 51 ---> true // 15 ---> false // Tu código: + if (num > 50){ + return true + } else{ + return false + } + } module.exports = mayorQueCincuenta; diff --git a/C5 Fundamentos Javascript/ejercicios/15.js b/C5 Fundamentos Javascript/ejercicios/15.js index 98648a7167..f7af6c1716 100644 --- a/C5 Fundamentos Javascript/ejercicios/15.js +++ b/C5 Fundamentos Javascript/ejercicios/15.js @@ -6,6 +6,12 @@ function esPar(num) { // 14 ---> true // 15 ---> false // Tu código: + if (num % 2 == 0){ + return true + } else{ + return false + } + } module.exports = esPar; diff --git a/C5 Fundamentos Javascript/ejercicios/16.js b/C5 Fundamentos Javascript/ejercicios/16.js index 7721e84f50..c2f743e6e1 100644 --- a/C5 Fundamentos Javascript/ejercicios/16.js +++ b/C5 Fundamentos Javascript/ejercicios/16.js @@ -6,6 +6,12 @@ function esImpar(num) { // 15 ---> true // 14 ---> false // Tu código: + if (num % 2 == 0){ + return false + } else{ + return true + } + } module.exports = esImpar; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/17.js b/C5 Fundamentos Javascript/ejercicios/17.js index dc0f6d6a95..50c93026dc 100644 --- a/C5 Fundamentos Javascript/ejercicios/17.js +++ b/C5 Fundamentos Javascript/ejercicios/17.js @@ -6,6 +6,14 @@ function esPositivo(num) { // Si el número es negativo ---> "Es negativo". // Si el número es 0, devuelve false. // Tu código: + if (num < 0){ + return "Es negativo" + } else if (num > 0){ + return "Es positivo" + } else { + return false + } + } module.exports = esPositivo; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/18.js b/C5 Fundamentos Javascript/ejercicios/18.js index 180f3bff3d..ae81c8d9be 100644 --- a/C5 Fundamentos Javascript/ejercicios/18.js +++ b/C5 Fundamentos Javascript/ejercicios/18.js @@ -8,6 +8,26 @@ function esVocal(letra) { // "n" ---> "Dato incorrecto" // "texto largo" ---> "Dato incorrecto" // Tu código: + switch (true) { + case letra == "a": + return "Es vocal" + break; + case letra == "e": + return "Es vocal" + break; + case letra == "i": + return "Es vocal" + break; + case letra == "o": + return "Es vocal" + break; + case letra == "u": + return "Es vocal" + break; + default: + return "Dato incorrecto" + break; + } } module.exports = esVocal; diff --git a/C5 Fundamentos Javascript/ejercicios/19.js b/C5 Fundamentos Javascript/ejercicios/19.js index eadd4aa24e..5e2316294b 100644 --- a/C5 Fundamentos Javascript/ejercicios/19.js +++ b/C5 Fundamentos Javascript/ejercicios/19.js @@ -5,6 +5,8 @@ function suma(x, y) { // 5, 5 ---> 10 // -5, 5 ---> 0 // Tu código: +let suma = x + y +return suma } module.exports = suma; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/20.js b/C5 Fundamentos Javascript/ejercicios/20.js index 85e2de4890..711838115d 100644 --- a/C5 Fundamentos Javascript/ejercicios/20.js +++ b/C5 Fundamentos Javascript/ejercicios/20.js @@ -5,6 +5,8 @@ function resta(x, y) { // 10, 5 ---> 5 // 5, 5 ---> 0 // Tu código: + let suma = x - y +return suma } module.exports = resta; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/21.js b/C5 Fundamentos Javascript/ejercicios/21.js index 747fe977f9..6a70aa6b56 100644 --- a/C5 Fundamentos Javascript/ejercicios/21.js +++ b/C5 Fundamentos Javascript/ejercicios/21.js @@ -5,6 +5,8 @@ function multiplica(x, y) { // 10, 5 ---> 50 // 5, 5 ---> 25 // Tu código: + let suma = x * y +return suma } module.exports = multiplica; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/22.js b/C5 Fundamentos Javascript/ejercicios/22.js index 57e0e9c6e7..9ffc163107 100644 --- a/C5 Fundamentos Javascript/ejercicios/22.js +++ b/C5 Fundamentos Javascript/ejercicios/22.js @@ -5,6 +5,8 @@ function divide(x, y) { // 10, 5 ---> 2 // 5, 5 ---> 1 // Tu código: + let suma = x / y +return suma } module.exports = divide; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/23.js b/C5 Fundamentos Javascript/ejercicios/23.js index 05b43b2135..1d64c8c227 100644 --- a/C5 Fundamentos Javascript/ejercicios/23.js +++ b/C5 Fundamentos Javascript/ejercicios/23.js @@ -5,6 +5,8 @@ function obtenerResto(x, y) { // 10, 5 ---> 0 // 16, 5 ---> 1 // Tu código: + let suma = x % y +return suma } module.exports = obtenerResto; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/24.js b/C5 Fundamentos Javascript/ejercicios/24.js index 0c25f1a616..a0ecea7099 100644 --- a/C5 Fundamentos Javascript/ejercicios/24.js +++ b/C5 Fundamentos Javascript/ejercicios/24.js @@ -4,6 +4,8 @@ function agregarSimboloExclamacion(str) { // Por ejemplo: // "hello world" ---> "hello world!" // Tu código: + let newStr = str + "!" + return newStr; } module.exports = agregarSimboloExclamacion; diff --git a/C5 Fundamentos Javascript/ejercicios/25.js b/C5 Fundamentos Javascript/ejercicios/25.js index 6e2e9ed067..10a4b23dcb 100644 --- a/C5 Fundamentos Javascript/ejercicios/25.js +++ b/C5 Fundamentos Javascript/ejercicios/25.js @@ -4,6 +4,8 @@ function combinarNombres(nombre, apellido) { // Por ejemplo: // "Soy", "Henry" ---> "Soy Henry" // Tu código: + let newStr = nombre + " " + apellido + return newStr; } module.exports = combinarNombres; diff --git a/C5 Fundamentos Javascript/ejercicios/26.js b/C5 Fundamentos Javascript/ejercicios/26.js index 2a0f6ceafc..04ad247059 100644 --- a/C5 Fundamentos Javascript/ejercicios/26.js +++ b/C5 Fundamentos Javascript/ejercicios/26.js @@ -4,6 +4,8 @@ function obtenerSaludo(nombre) { // Ejemplo: "Martin" ---> "Hola Martin!" // Retorna el nuevo string. // Tu código: + let newStr = "Hola " + nombre + "!" + return newStr; } module.exports = obtenerSaludo; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/27.js b/C5 Fundamentos Javascript/ejercicios/27.js index e786d71a11..5cc327aa11 100644 --- a/C5 Fundamentos Javascript/ejercicios/27.js +++ b/C5 Fundamentos Javascript/ejercicios/27.js @@ -5,6 +5,8 @@ function obtenerAreaRectangulo(alto, ancho) { // 2, 2 ---> 4 // 0, 2 ---> 2 // Tu código: + let newStr = alto * ancho + return newStr; } module.exports = obtenerAreaRectangulo; diff --git a/C5 Fundamentos Javascript/ejercicios/28.js b/C5 Fundamentos Javascript/ejercicios/28.js index c86f27e883..3307995194 100644 --- a/C5 Fundamentos Javascript/ejercicios/28.js +++ b/C5 Fundamentos Javascript/ejercicios/28.js @@ -5,6 +5,8 @@ function retornarPerimetro(lado) { // 2 ---> 8 // 0 ---> 0 // Tu código: + let newStr = lado * 4 + return newStr; } module.exports = retornarPerimetro; diff --git a/C5 Fundamentos Javascript/ejercicios/29.js b/C5 Fundamentos Javascript/ejercicios/29.js index 8e7d52ff15..a030537c05 100644 --- a/C5 Fundamentos Javascript/ejercicios/29.js +++ b/C5 Fundamentos Javascript/ejercicios/29.js @@ -5,6 +5,8 @@ function areaDelTriangulo(base, altura) { // 10, 5 ---> 25 // 0, 10 ---> 0 // Tu código: + let newStr = (base * altura)/ 2 + return newStr; } module.exports = areaDelTriangulo; diff --git a/C5 Fundamentos Javascript/ejercicios/30.js b/C5 Fundamentos Javascript/ejercicios/30.js index 6f0882f77d..52dd3ce7b7 100644 --- a/C5 Fundamentos Javascript/ejercicios/30.js +++ b/C5 Fundamentos Javascript/ejercicios/30.js @@ -7,6 +7,8 @@ function deEuroAdolar(euro) { // 1 ---> 1.20 // 0 ---> 0 // Tu código: + let newStr = euro * 1.20 + return newStr; } module.exports = deEuroAdolar; diff --git a/C5 Fundamentos Javascript/ejercicios/31.js b/C5 Fundamentos Javascript/ejercicios/31.js index 823f0fb17b..f3a73747ab 100644 --- a/C5 Fundamentos Javascript/ejercicios/31.js +++ b/C5 Fundamentos Javascript/ejercicios/31.js @@ -7,6 +7,8 @@ function elevarAlCuadrado(num) { // 6 ---> 36 // 0 ---> 0 // Tu código: + let newStr = Math.pow(num, 2) + return newStr; } module.exports = elevarAlCuadrado; diff --git a/C5 Fundamentos Javascript/ejercicios/32.js b/C5 Fundamentos Javascript/ejercicios/32.js index 7150676698..733095fb16 100644 --- a/C5 Fundamentos Javascript/ejercicios/32.js +++ b/C5 Fundamentos Javascript/ejercicios/32.js @@ -7,6 +7,8 @@ function elevarAlCubo(num) { // 3 ---> 27 // 0 ---> 0 // Tu código: + let newStr = Math.pow(num, 3) + return newStr; } module.exports = elevarAlCubo; diff --git a/C5 Fundamentos Javascript/ejercicios/33.js b/C5 Fundamentos Javascript/ejercicios/33.js index 09944ed939..ba6e1dbbc0 100644 --- a/C5 Fundamentos Javascript/ejercicios/33.js +++ b/C5 Fundamentos Javascript/ejercicios/33.js @@ -7,6 +7,8 @@ function elevar(num, exponent) { // 2, 2 ---> 4 // 0, 5 ---> 0 // Tu código: + let newStr = Math.pow(num, exponent); + return newStr; } module.exports = elevar; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/34.js b/C5 Fundamentos Javascript/ejercicios/34.js index 2fff9db0e4..4d5c302e89 100644 --- a/C5 Fundamentos Javascript/ejercicios/34.js +++ b/C5 Fundamentos Javascript/ejercicios/34.js @@ -7,6 +7,8 @@ function redondearNumero(num) { // 1.5 ---> 2 // 0.1 ---> 0 // Tu código: + let newStr = Math.round(num); + return newStr; } module.exports = redondearNumero; diff --git a/C5 Fundamentos Javascript/ejercicios/35.js b/C5 Fundamentos Javascript/ejercicios/35.js index 1987c119d4..82709cc28d 100644 --- a/C5 Fundamentos Javascript/ejercicios/35.js +++ b/C5 Fundamentos Javascript/ejercicios/35.js @@ -7,6 +7,8 @@ function redondearHaciaArriba(num) { // 2.5 ---> 3 // 0.1 ---> 1 // Tu código: + let newStr = Math.ceil(num); + return newStr; } module.exports = redondearHaciaArriba; \ No newline at end of file diff --git a/C5 Fundamentos Javascript/ejercicios/36.js b/C5 Fundamentos Javascript/ejercicios/36.js index d0288d803f..580b52113c 100644 --- a/C5 Fundamentos Javascript/ejercicios/36.js +++ b/C5 Fundamentos Javascript/ejercicios/36.js @@ -3,6 +3,8 @@ function numeroRandom() { // La función numeroRandom debe generar un número al azar entre 0 y 1 y retornarlo. // Tu código: + let newStr = Math.random() + return newStr; } module.exports = numeroRandom; diff --git a/C6 Bucles/ejercicios/01.js b/C6 Bucles/ejercicios/01.js index 95f2825332..b3ece1790e 100644 --- a/C6 Bucles/ejercicios/01.js +++ b/C6 Bucles/ejercicios/01.js @@ -3,6 +3,11 @@ function esIgualYNegativo(a, b) { // Determina si son iguales y son ambos negativos. // De ser así, retorna true, de lo contrario, retorna false. // Tu código: +if (a == b && a < 0 && b < 0){ + return true; +} +return false + } module.exports = esIgualYNegativo; diff --git a/C6 Bucles/ejercicios/02.js b/C6 Bucles/ejercicios/02.js index a98deee96a..ab679fe949 100644 --- a/C6 Bucles/ejercicios/02.js +++ b/C6 Bucles/ejercicios/02.js @@ -2,6 +2,10 @@ function esVerdaderoYFalso(booleano1, booleano2) { // La función recibe dos argumentos "booleano1" y "booleano2". // Retorna true si ambos son verdaderos, caso contrario, retorna false. // Tu código: + if (booleano1 && booleano2){ + return true; + } + return false; } module.exports = esVerdaderoYFalso; diff --git a/C6 Bucles/ejercicios/03.js b/C6 Bucles/ejercicios/03.js index 95d1b1f4c3..1dec1db0b7 100644 --- a/C6 Bucles/ejercicios/03.js +++ b/C6 Bucles/ejercicios/03.js @@ -3,6 +3,10 @@ function obtenerMayor(x, y) { // Retorna el número más grande. // Si son iguales, retornar cualquiera de los dos. // Tu código: + if(x > y){ + return x + } + return y; } module.exports = obtenerMayor; diff --git a/C6 Bucles/ejercicios/04.js b/C6 Bucles/ejercicios/04.js index 7ef7a58d03..fb222831bf 100644 --- a/C6 Bucles/ejercicios/04.js +++ b/C6 Bucles/ejercicios/04.js @@ -3,6 +3,10 @@ function mayoriaDeEdad(edad) { // Si tiene 18 años o más, retorna el string: "Allowed". // Caso contrario: "Not allowed". // Tu código: + if(edad >=18){ + return "Allowed"; + } + return "Not allowed"; } module.exports = mayoriaDeEdad; diff --git a/C6 Bucles/ejercicios/05.js b/C6 Bucles/ejercicios/05.js index ee7e89c431..41468d67ce 100644 --- a/C6 Bucles/ejercicios/05.js +++ b/C6 Bucles/ejercicios/05.js @@ -2,6 +2,8 @@ function esVerdadero(valor) { // Si "valor" es verdadero, retorna "Soy verdadero". // Caso contrario, retorna "Soy falso". // Tu código: + if(valor) return "Soy verdadero"; + return "Soy falso" } module.exports = esVerdadero; diff --git a/C6 Bucles/ejercicios/06.js b/C6 Bucles/ejercicios/06.js index b7c047365b..f2a4454fac 100644 --- a/C6 Bucles/ejercicios/06.js +++ b/C6 Bucles/ejercicios/06.js @@ -2,6 +2,8 @@ function tieneTresDigitos(num) { // Si el número recibido tiene tres dígitos, retorna true. // Caso contrario, retorna false. // Tu código: + if(num > 99 && num < 1000) return true; + return false; } module.exports = tieneTresDigitos; diff --git a/C6 Bucles/ejercicios/07.js b/C6 Bucles/ejercicios/07.js index 5191b315af..11d253b4db 100644 --- a/C6 Bucles/ejercicios/07.js +++ b/C6 Bucles/ejercicios/07.js @@ -3,6 +3,8 @@ function esParYDivisiblePorTres(a) { // Retorna true si este es par y divisible por tres a la vez. // Retorna false si no lo es. // Tu código: + if(a % 2 == 0 && a % 3 == 0) return true; + return false; } module.exports = esParYDivisiblePorTres; \ No newline at end of file diff --git a/C6 Bucles/ejercicios/08.js b/C6 Bucles/ejercicios/08.js index bb5f11d4c0..1e767c7edd 100644 --- a/C6 Bucles/ejercicios/08.js +++ b/C6 Bucles/ejercicios/08.js @@ -3,6 +3,8 @@ function esPositivoOInferiorA10(a) { // Retorna true si es positivo y menor que 10. // Retorna false en caso contrario. // Tu código: + if(a >= 0 && a<10) return true; + return false; } module.exports = esPositivoOInferiorA10; diff --git a/C6 Bucles/ejercicios/09.js b/C6 Bucles/ejercicios/09.js index f3898b19c7..4f1cdcd04a 100644 --- a/C6 Bucles/ejercicios/09.js +++ b/C6 Bucles/ejercicios/09.js @@ -5,6 +5,17 @@ function conection(status) { // De lo contrario, presumimos que el usuario está "Offline". // Retornar el estado de conexión del usuario. // Tu código: + switch (true) { + case status == 1: + return "Online"; + break; + case status == 2: + return "Away"; + break; + default: + return "Offline" + break; + } } module.exports = conection; diff --git a/C6 Bucles/ejercicios/10.js b/C6 Bucles/ejercicios/10.js index 2620c50f93..5d177d2718 100644 --- a/C6 Bucles/ejercicios/10.js +++ b/C6 Bucles/ejercicios/10.js @@ -2,6 +2,8 @@ function esDiezOCinco(num) { // Retornar true si "num" es 10 o 5. // De lo contrario, retornar false. // Tu código: + if(num == 10 || num == 5) return true; + return false; } module.exports = esDiezOCinco; diff --git a/C6 Bucles/ejercicios/11.js b/C6 Bucles/ejercicios/11.js index f35ed4ab3d..d8298bee54 100644 --- a/C6 Bucles/ejercicios/11.js +++ b/C6 Bucles/ejercicios/11.js @@ -2,6 +2,8 @@ function estaEnRango(num) { // Retorna true si "num" es menor que 50 y mayor que 20. // De lo contrario, retornar false. // Tu código: + if(num < 50 && num > 20) return true; + return false; } module.exports = estaEnRango; diff --git a/C6 Bucles/ejercicios/12.js b/C6 Bucles/ejercicios/12.js index b61a3aec43..fbcf53f87b 100644 --- a/C6 Bucles/ejercicios/12.js +++ b/C6 Bucles/ejercicios/12.js @@ -4,6 +4,20 @@ function fizzBuzz(num) { // Si "num" es divisible entre 3 y 5 (ambos), retorna "fizzbuzz". // De lo contrario, retorna false. // Tu código: + switch (true) { + case num % 3 == 0 && num % 5 == 0: + return "fizzbuzz" + break; + case num % 3 == 0: + return "fizz"; + break; + case num % 5 == 0: + return "buzz" + break; + default: + return false; + break; + } } module.exports = fizzBuzz; diff --git a/C6 Bucles/ejercicios/13.js b/C6 Bucles/ejercicios/13.js index 76e254264a..3692c84a44 100644 --- a/C6 Bucles/ejercicios/13.js +++ b/C6 Bucles/ejercicios/13.js @@ -5,6 +5,8 @@ function esEntero(num) { // Ejemplo: (-10) ---> true // De lo contrario, retorna false. // Tu código: + if(Number.isInteger(num)) return true; + return false; } module.exports = esEntero; diff --git a/C6 Bucles/ejercicios/14.js b/C6 Bucles/ejercicios/14.js index 285d4fdfe2..3c00096903 100644 --- a/C6 Bucles/ejercicios/14.js +++ b/C6 Bucles/ejercicios/14.js @@ -6,6 +6,24 @@ function operadoresLogicos(num1, num2, num3) { // Si todos los argumentos son cero, retorna ---> "Error". // Si no se cumple ninguna de las condiciones anteriores, retorna false. // Tu código: + switch (true) { + case num1 > num2 && num1 > num3 && num1 > 0: + return "Numero 1 es mayor y positivo" + break; + case num1 <0 || num2 <0 || num3 <0: + return "Hay negativos" + break; + case num3 > num2 && num3 > num1: + num3 = num3 + 1; + return num3; + break; + case num1 ==0 || num2==0 || num3==0: + return "Error" + break; + default: + return false; + break; + } } module.exports = operadoresLogicos; diff --git a/C6 Bucles/ejercicios/15.js b/C6 Bucles/ejercicios/15.js index 906f514225..3eb2e1ee95 100644 --- a/C6 Bucles/ejercicios/15.js +++ b/C6 Bucles/ejercicios/15.js @@ -6,6 +6,33 @@ function obtenerDiaSemana(numero) { // Si el número no corresponde a un día de la semana, retorna // el string "No es un dia de la semana" // Tu código: + switch (true) { + case numero == 1: + return "Lunes" + break; + case numero == 2: + return "Martes" + break; + case numero == 3: + return "Miercoles" + break; + case numero == 4: + return "Jueves" + break; + case numero == 5: + return "Viernes" + break; + case numero == 6: + return "Sabado" + break; + case numero == 7: + return "Domingo" + break; + default: + return "No es un dia de la semana" + break; + } + } module.exports = obtenerDiaSemana; \ No newline at end of file diff --git a/C6 Bucles/ejercicios/16.js b/C6 Bucles/ejercicios/16.js index 01a50c9f01..03fa1d4f76 100644 --- a/C6 Bucles/ejercicios/16.js +++ b/C6 Bucles/ejercicios/16.js @@ -5,6 +5,20 @@ function saludo(idioma) { // Si "idioma" es "ingles", devuelve "Hello!". // Si "idioma" no es ninguno de los anteriores o es `undefined`, devuelve "Hola!". // Tu código: + switch (true) { + case idioma == "aleman": + return "Guten Tag!" + break; + case idioma == "mandarin": + return "Ni Hao!" + break; + case idioma == "ingles": + return "Hello!" + break; + default: + return "Hola!" + break; + } } module.exports = saludo; diff --git a/C6 Bucles/ejercicios/17.js b/C6 Bucles/ejercicios/17.js index 3dcc148517..8b78c3547a 100644 --- a/C6 Bucles/ejercicios/17.js +++ b/C6 Bucles/ejercicios/17.js @@ -7,6 +7,23 @@ function colors(color) { // Si no es ninguno de esos colores --> "Color not found". // PISTA: utilizar el statement SWITCH. // Tu código: + switch (true) { + case color == "blue": + return "This is blue" + break; + case color == "red": + return "This is red" + break; + case color == "green": + return "This is green" + break; + case color == "orange": + return "This is orange" + break; + default: + return "Color not found" + break; + } } module.exports = colors; diff --git a/C6 Bucles/ejercicios/18.js b/C6 Bucles/ejercicios/18.js index e7183ff019..63247e6a69 100644 --- a/C6 Bucles/ejercicios/18.js +++ b/C6 Bucles/ejercicios/18.js @@ -2,6 +2,14 @@ function productoEntreNúmeros(a, b) { // Dados dos argumentos "a" y "b", devuelve el producto de todos // los números entre a y b (inclusive). // Tu código: + if(a===b) return a; + let prod = a; + while (a!=b) { + prod = prod * (a+1) + a++ + } + if(prod == -0) return 0; + return prod; } module.exports = productoEntreNúmeros; \ No newline at end of file diff --git a/C6 Bucles/ejercicios/19.js b/C6 Bucles/ejercicios/19.js index 41c47d54eb..32578b3531 100644 --- a/C6 Bucles/ejercicios/19.js +++ b/C6 Bucles/ejercicios/19.js @@ -2,6 +2,11 @@ function sumarHastaN(n) { // La función recibe un número "n" por argumento. // Devuelve la suma de todos los números desde 1 hasta n. // Tu código: + let suma = 0 + for (let i = 0; i <= n; i++) { + suma = suma + i; + } + return suma; } module.exports = sumarHastaN; diff --git a/C6 Bucles/ejercicios/20.js b/C6 Bucles/ejercicios/20.js index 4c835a54d4..970baa209d 100644 --- a/C6 Bucles/ejercicios/20.js +++ b/C6 Bucles/ejercicios/20.js @@ -3,6 +3,15 @@ function sumarHastaNConBreak(n) { // Devuelve la suma de todos los números desde 1 hasta n. // Si la suma supera a 100, detén el bucle usando break. // Tu código: + let suma = 0 + for (let i = 0; i <= n; i++) { + suma = suma + i; + if(suma>100){ + break; + } + } + return suma; } + module.exports = sumarHastaNConBreak; diff --git a/C6 Bucles/ejercicios/21.js b/C6 Bucles/ejercicios/21.js index 1107bf2a11..2fd2c8c22d 100644 --- a/C6 Bucles/ejercicios/21.js +++ b/C6 Bucles/ejercicios/21.js @@ -4,6 +4,18 @@ function esPotenciaDeDos(numero) { // Devuelve true si lo es, sino devuelve false. // PISTA: Utiliza un bucle while. // Tu código: + let pot = 2 + let i = 0 + while (i<10) { + if(numero % 2 !== 0) return false; + if(numero == 2) return true; + if(numero == 2*pot){ + return true; + } + pot = pot * 2 + i++ + } + return false; } module.exports = esPotenciaDeDos; diff --git a/C6 Bucles/ejercicios/22.js b/C6 Bucles/ejercicios/22.js index 308536602f..d3e6c81224 100644 --- a/C6 Bucles/ejercicios/22.js +++ b/C6 Bucles/ejercicios/22.js @@ -3,6 +3,13 @@ function doWhile(num) { // Retorna el valor final. // PISTA: Utiliza el bucle do-while. // Tu código: + let i = 0 + let suma = num; + do { + suma += 5 + i++ + } while (i<8); + return suma; } module.exports = doWhile; \ No newline at end of file diff --git a/C6 Bucles/ejercicios/23.js b/C6 Bucles/ejercicios/23.js index ebe222a114..38cd033486 100644 --- a/C6 Bucles/ejercicios/23.js +++ b/C6 Bucles/ejercicios/23.js @@ -6,6 +6,14 @@ function esNumeroPrimo(numero) { // IMPORTANTE: Recuerda que un número primo es aquel que // solo es divisible por sí mismo y por 1. // Tu código: + let dividendo = [3, 5, 7] + if (numero == 2) return true; + if (numero % 2 == 0) return false; + for (let i = 0; i < dividendo.length; i++){ + if (numero == dividendo[i]) return true; + if (numero % dividendo[i] == 0) return false; +} +return true; } module.exports = esNumeroPrimo; diff --git a/C7 Arrays/ejercicios/01.js b/C7 Arrays/ejercicios/01.js index 508c5fd8a1..be0417d4c7 100644 --- a/C7 Arrays/ejercicios/01.js +++ b/C7 Arrays/ejercicios/01.js @@ -1,6 +1,7 @@ function devolverPrimerElemento(array) { // Retornar el primer elemento del arreglo recibido. // Tu código: + return array[0]; } module.exports = devolverPrimerElemento; diff --git a/C7 Arrays/ejercicios/02.js b/C7 Arrays/ejercicios/02.js index 3c40692116..a6b2fd7467 100644 --- a/C7 Arrays/ejercicios/02.js +++ b/C7 Arrays/ejercicios/02.js @@ -1,6 +1,7 @@ function devolverUltimoElemento(array) { // Retornar el último elemento del arreglo recibido. // Tu código: + return array[array.length-1]; } module.exports = devolverUltimoElemento; diff --git a/C7 Arrays/ejercicios/03.js b/C7 Arrays/ejercicios/03.js index 1170d0a120..1395c1c251 100644 --- a/C7 Arrays/ejercicios/03.js +++ b/C7 Arrays/ejercicios/03.js @@ -1,6 +1,7 @@ function obtenerLargoDelArray(array) { // Retornar la longitud del arreglo recibido. // Tu código: + return array.length; } module.exports = obtenerLargoDelArray; diff --git a/C7 Arrays/ejercicios/04.js b/C7 Arrays/ejercicios/04.js index f8433b6134..b505f33938 100644 --- a/C7 Arrays/ejercicios/04.js +++ b/C7 Arrays/ejercicios/04.js @@ -2,6 +2,8 @@ function agregarItemAlFinalDelArray(array, elemento) { // Agrega el "elemento" al final del arreglo recibido. // Retorna el arreglo. // Tu código: + array.push(elemento); + return array; } module.exports = agregarItemAlFinalDelArray; diff --git a/C7 Arrays/ejercicios/05.js b/C7 Arrays/ejercicios/05.js index 9d17508d9d..ffc571b81b 100644 --- a/C7 Arrays/ejercicios/05.js +++ b/C7 Arrays/ejercicios/05.js @@ -2,6 +2,8 @@ function agregarItemAlComienzoDelArray(array, elemento) { // Agrega el "elemento" al comienzo del arreglo recibido. // Retorna el arreglo. // Tu código: + array.unshift(elemento); + return array; } module.exports = agregarItemAlComienzoDelArray; diff --git a/C7 Arrays/ejercicios/06.js b/C7 Arrays/ejercicios/06.js index 0d093fec57..2fa74769b2 100644 --- a/C7 Arrays/ejercicios/06.js +++ b/C7 Arrays/ejercicios/06.js @@ -1,6 +1,11 @@ function invertirArray(array) { // Invierte el arreglo array recibido por argumento. // Tu código: + let newArray = []; + for (let i = 0; i < array.length; i++) { + newArray.unshift(array[i]); + } + return newArray; } module.exports = invertirArray; diff --git a/C7 Arrays/ejercicios/07.js b/C7 Arrays/ejercicios/07.js index ef9535455e..3a6f9f426e 100644 --- a/C7 Arrays/ejercicios/07.js +++ b/C7 Arrays/ejercicios/07.js @@ -2,6 +2,8 @@ function ordenarArray(array) { // Ordena los elementos del areglo array de menor a mayor. // Devuelve el arreglo resultante. // Tu código: + array.sort(); + return array; } module.exports = ordenarArray; diff --git a/C7 Arrays/ejercicios/08.js b/C7 Arrays/ejercicios/08.js index 46dcf9a08f..de6790ee59 100644 --- a/C7 Arrays/ejercicios/08.js +++ b/C7 Arrays/ejercicios/08.js @@ -3,6 +3,13 @@ function encontrarElemento(num, array) { // Si lo encuentras debes retornar el INDICE en el que se encuentra dentro del array. // Si no se encuentra, retorna -1. // Tu código: + if(array.includes(num)){ + for (let i = 0; i < array.length; i++) { + if(num === array[i]) + return i; + } + } + return -1; } module.exports = encontrarElemento; diff --git a/C7 Arrays/ejercicios/09.js b/C7 Arrays/ejercicios/09.js index 5f9b6248d8..601e3831ea 100644 --- a/C7 Arrays/ejercicios/09.js +++ b/C7 Arrays/ejercicios/09.js @@ -2,6 +2,8 @@ function obtenerElementoAleatorio(array) { // Devuelve un elemento aleatorio del arreglo array. // PISTA: Usa el método Math.random(). // Tu código: + let numero = Math.floor(Math.random()*array.length) + return array[numero]; } module.exports = obtenerElementoAleatorio; diff --git a/C7 Arrays/ejercicios/10.js b/C7 Arrays/ejercicios/10.js index dea50da555..ce648528b3 100644 --- a/C7 Arrays/ejercicios/10.js +++ b/C7 Arrays/ejercicios/10.js @@ -1,6 +1,9 @@ function obtenerPrimerStringLargo(array) { // Devuelve el primer string con más de 5 caracteres en el array. // Tu código: + for (let i = 0; i < array.length; i++) { + if(array[i].length >= 5) return array[i]; + } } module.exports = obtenerPrimerStringLargo; diff --git a/C7 Arrays/ejercicios/11.js b/C7 Arrays/ejercicios/11.js index 3194c62196..5dd0c772d0 100644 --- a/C7 Arrays/ejercicios/11.js +++ b/C7 Arrays/ejercicios/11.js @@ -2,6 +2,8 @@ function duplicarElementos(array) { // Duplica (multiplica x2) cada elemento del array de números. // Devuelve un array con los duplicados. // Tu código: + let newArray = array.map((num) => num * 2); + return newArray; } module.exports = duplicarElementos; diff --git a/C7 Arrays/ejercicios/12.js b/C7 Arrays/ejercicios/12.js index 2df8d8eb7d..a02c187224 100644 --- a/C7 Arrays/ejercicios/12.js +++ b/C7 Arrays/ejercicios/12.js @@ -2,6 +2,11 @@ function convertirStringAMayusculas(array) { // Convierte a mayúsculas todos los strings del array. // Retorna el arreglo resultante. // Tu código: + let newArray = []; + for (let i = 0; i < array.length; i++) { + newArray.push(array[i].toUpperCase()); + } + return newArray; } module.exports = convertirStringAMayusculas; diff --git a/C7 Arrays/ejercicios/13.js b/C7 Arrays/ejercicios/13.js index 037a01b1b9..b8d8fece8e 100644 --- a/C7 Arrays/ejercicios/13.js +++ b/C7 Arrays/ejercicios/13.js @@ -1,6 +1,13 @@ function filtrarNumerosPares(array) { // Devuelve un arreglo solo con los números pares presentes en el array. // Tu código: + let newArray = []; + for (let i = 0; i < array.length; i++) { + if (array[i]% 2 == 0) { + newArray.push(array[i]) + } + } + return newArray; } module.exports = filtrarNumerosPares; diff --git a/C7 Arrays/ejercicios/14.js b/C7 Arrays/ejercicios/14.js index 28cc42c259..940ecf0f6c 100644 --- a/C7 Arrays/ejercicios/14.js +++ b/C7 Arrays/ejercicios/14.js @@ -1,6 +1,13 @@ function contarElementosMayoresA10(array) { // Cuenta y devuelve la cantidad de elementos mayores a 10 en el array de números. // Tu código: + let mayores = []; + for(let i = 0; i < array.length; i++){ + if (array[i] > 10){ + mayores.push(array[i]) + } + } + return mayores.length; } module.exports = contarElementosMayoresA10; diff --git a/C7 Arrays/ejercicios/15.js b/C7 Arrays/ejercicios/15.js index cf07316133..db14c5e826 100644 --- a/C7 Arrays/ejercicios/15.js +++ b/C7 Arrays/ejercicios/15.js @@ -2,6 +2,14 @@ function encontrarIndiceMayor(array) { // Encuentra el índice del número más grande en el array de números. // Devuelve el valor de este índice. // Tu código: +let mayor = -100; +for (let i = 0; i < array.length; i++) { + if(mayor < array[i]){ + mayor = array[i] + } +} +if(array.length == 0) return 0; +return array.indexOf(mayor); } module.exports = encontrarIndiceMayor; diff --git a/C7 Arrays/ejercicios/16.js b/C7 Arrays/ejercicios/16.js index 6e6019e704..071754a0f5 100644 --- a/C7 Arrays/ejercicios/16.js +++ b/C7 Arrays/ejercicios/16.js @@ -2,6 +2,11 @@ function multiplicarElementosPorIndice(array) { // Multiplica cada elemento del array por su índice. // Devuelve el nuevo arreglo con los resultados. // Tu código: + let multiplicado = []; + for(let i = 0; i < array.length; i++){ + multiplicado.push(i * array[i]) + } + return multiplicado; } module.exports = multiplicarElementosPorIndice; diff --git a/C7 Arrays/ejercicios/17.js b/C7 Arrays/ejercicios/17.js index edf8ab42f2..72840741fa 100644 --- a/C7 Arrays/ejercicios/17.js +++ b/C7 Arrays/ejercicios/17.js @@ -1,6 +1,11 @@ function agregarNumeros(arrayOfNums) { // Suma todos los elementos de arrayOfNums y retorna el resultado. // Tu código: + let sumaTotal = 0; + for(let i = 0; i < arrayOfNums.length; i++){ + sumaTotal += arrayOfNums[i]; + } + return sumaTotal; } module.exports = agregarNumeros; diff --git a/C7 Arrays/ejercicios/18.js b/C7 Arrays/ejercicios/18.js index 580e26c583..b710a3ce03 100644 --- a/C7 Arrays/ejercicios/18.js +++ b/C7 Arrays/ejercicios/18.js @@ -1,6 +1,11 @@ function promedioResultadosTest(resultadosTest) { // Itera sobre los elementos del arreglo resultadosTest y devuelve el promedio de las notas. // Tu código: + let sumaTotal = 0; + for(let i = 0; i < resultadosTest.length; i++){ + sumaTotal += resultadosTest[i]; + } + return sumaTotal/resultadosTest.length; } module.exports = promedioResultadosTest; diff --git a/C7 Arrays/ejercicios/19.js b/C7 Arrays/ejercicios/19.js index 4aed7fecae..b327400d8f 100644 --- a/C7 Arrays/ejercicios/19.js +++ b/C7 Arrays/ejercicios/19.js @@ -3,6 +3,13 @@ function multiplicarArgumentos() { // Si no se pasan argumentos retorna 0. Si se pasa un argumento, simplemente retórnalo. // [PISTA]: "arguments" es un arreglo. // Tu código: + if (arguments.length == 0) return 0; + if (arguments.length == 1) return arguments[0]; + let multiplicados = 1; + for (let i = 0; i < arguments.length; i++){ + multiplicados = multiplicados * arguments[i] + } + return multiplicados; } module.exports = multiplicarArgumentos; diff --git a/C7 Arrays/ejercicios/20.js b/C7 Arrays/ejercicios/20.js index bcce3a3dbc..79465da022 100644 --- a/C7 Arrays/ejercicios/20.js +++ b/C7 Arrays/ejercicios/20.js @@ -2,6 +2,12 @@ function todosIguales(array) { // Si todos los elementos del arreglo son iguales, retornar true. // Caso contrario, retornar false. // Tu código: + for(let i = 0; i < array.length; i++){ + for(let j = 1; j < array.length; j++){ + if(array[i] !== array[j]) return false; + } + } + return true; } module.exports = todosIguales; diff --git a/C7 Arrays/ejercicios/21.js b/C7 Arrays/ejercicios/21.js index 2dcba2d8e7..c43a431f8e 100644 --- a/C7 Arrays/ejercicios/21.js +++ b/C7 Arrays/ejercicios/21.js @@ -2,7 +2,15 @@ function mesesDelAño(array) { // El array contiene algunos meses del año desordenados. Debes recorrerlo, buscar los meses "Enero", // "Marzo" y "Noviembre", guardarlos en un nuevo arreglo y retornarlo. // Si alguno de los meses no está, retornar el string: "No se encontraron los meses pedidos". - // Tu código: + // Tu código + let meses = [] + for(let i = 0; i < array.length; i++){ + if(array[i] == "Enero" ||array[i] == "Marzo" ||array[i] == "Noviembre"){ + meses.push(array[i]) + } + } + if(meses.length<3) return "No se encontraron los meses pedidos"; + return meses; } module.exports = mesesDelAño; diff --git a/C7 Arrays/ejercicios/22.js b/C7 Arrays/ejercicios/22.js index 00e9aae5e9..11f8a0412b 100644 --- a/C7 Arrays/ejercicios/22.js +++ b/C7 Arrays/ejercicios/22.js @@ -2,6 +2,13 @@ function tablaDelSeis() { // Devuelve un arreglo con los resultados de la tabla de multiplicar del 6 en orden creciente. // Desde 0 al 60. // Tu código: + let tablaSeis = []; + for(let i = 0; i <= 10; i++){ + let multi = 0; + multi = i * 6; + tablaSeis.push(multi) + } + return tablaSeis; } module.exports = tablaDelSeis; diff --git a/C7 Arrays/ejercicios/23.js b/C7 Arrays/ejercicios/23.js index 408aebb292..b01304ecc5 100644 --- a/C7 Arrays/ejercicios/23.js +++ b/C7 Arrays/ejercicios/23.js @@ -3,6 +3,14 @@ function breakStatement(num) { // Guardar cada nuevo valor en un arreglo y retórnarlo. // Si en algún momento el valor de la suma y la cantidad de iteraciones coinciden, debe interrumpirse la ejecución y retornar el string: "Se interrumpió la ejecución". // Tu código: + let numeros = []; + for (let i = 0; i <= 9; i++) { + num += 2; + numeros.push(num); + if(num == i) return "Se interrumpió la ejecución"; + } + return numeros; + } module.exports = breakStatement; diff --git a/C7 Arrays/ejercicios/24.js b/C7 Arrays/ejercicios/24.js index 522c2d5e4d..3f2952afde 100644 --- a/C7 Arrays/ejercicios/24.js +++ b/C7 Arrays/ejercicios/24.js @@ -5,6 +5,15 @@ function continueStatement(num) { // se continúa con la siguiente iteración. // PISTA: Utiliza el statement 'continue'. // Tu código: + let numeros = []; + for (let i = 0; i < 10; i++) { + if(i === 5) { + continue; + } + num += 2; + numeros.push(num); + } + return numeros; } module.exports = continueStatement; diff --git a/C7 Arrays/ejercicios/25.js b/C7 Arrays/ejercicios/25.js index 2d145505bb..044aadbf75 100644 --- a/C7 Arrays/ejercicios/25.js +++ b/C7 Arrays/ejercicios/25.js @@ -3,6 +3,14 @@ function contarParesConContinue(numeros) { // Devuelve la cantidad de números pares que hay en el array. // Evita los impares utilizando continue. // Tu código: + let pares = []; + for (let i = 0; i < numeros.length; i++) { + if(numeros[i] % 2 !== 0){ + continue; + } + pares.push(numeros[i]); + } + return pares.length; } module.exports = contarParesConContinue; diff --git a/C7 Arrays/ejercicios/26.js b/C7 Arrays/ejercicios/26.js index 4d5a5d9aa4..f04a22bd4d 100644 --- a/C7 Arrays/ejercicios/26.js +++ b/C7 Arrays/ejercicios/26.js @@ -3,6 +3,15 @@ function encontrarPrimerMultiploDeN(n, secuencia) { // Devuelve el primer múltiplo de n que encuentres en la secuencia de números. // Usa un break para detener el bucle una vez halles el múltiplo. // Tu código: + for (let i = 0; i < secuencia.length; i++) { + if(secuencia[i] == 1){ + continue; + } + if(n % secuencia[i] == 0){ + return secuencia[i]; + break; + } + } } module.exports = encontrarPrimerMultiploDeN; \ No newline at end of file diff --git a/C7 Arrays/ejercicios/27.js b/C7 Arrays/ejercicios/27.js index b5d8565c5f..9c74bd7d58 100644 --- a/C7 Arrays/ejercicios/27.js +++ b/C7 Arrays/ejercicios/27.js @@ -4,6 +4,8 @@ function dePalabrasAFrase(palabras) { // con un espacio entre cada palabra. // Ejemplo: ['Hello', 'world!'] -> 'Hello world!'. // Tu código: + const concatenadas = palabras.join(" "); + return concatenadas; } module.exports = dePalabrasAFrase; diff --git a/C7 Arrays/ejercicios/28.js b/C7 Arrays/ejercicios/28.js index a1a65816b6..319564ccc0 100644 --- a/C7 Arrays/ejercicios/28.js +++ b/C7 Arrays/ejercicios/28.js @@ -3,6 +3,10 @@ function esArrayNoVacio(arr) { // Comprueba si este argumento es un array y si tiene al menos un elemento. // Si es así, retorna true, de lo contrario, retorna false. // Tu código: + if(Array.isArray(arr) && arr.length > 0){ + return true + } + return false; } module.exports = esArrayNoVacio; \ No newline at end of file diff --git a/C7 Arrays/ejercicios/29.js b/C7 Arrays/ejercicios/29.js index de8a058efa..28976be2c2 100644 --- a/C7 Arrays/ejercicios/29.js +++ b/C7 Arrays/ejercicios/29.js @@ -4,6 +4,14 @@ function encontrarNumeroFaltante(numeros) { // y retórnalo. // Devuelve null si el array es vacío o si no hay números faltantes. // Tu código: + let suma = 1 + for (let i = 0; i < numeros.length; i++) { + if(suma !== numeros[i]){ + return suma; + } + suma++; + } + return null; } module.exports = encontrarNumeroFaltante; \ No newline at end of file diff --git a/C7 Arrays/ejercicios/30.js b/C7 Arrays/ejercicios/30.js index 74cdb5570d..dff807a533 100644 --- a/C7 Arrays/ejercicios/30.js +++ b/C7 Arrays/ejercicios/30.js @@ -2,6 +2,17 @@ function encontrarElementoRepetido(numeros) { // La función recibe un argumento "numeros" que es un array de números. // Retorna el primer elemento repetido que se encuentre en el array. // Tu código: + for (let i = 0; i < numeros.length; i++) { + let suma = 0 + for (let j = 0; j < numeros.length; j++) { + if(numeros[i] == numeros[j]){ + suma++; + } + if(suma == 2){ + return numeros[i] + } + } + } } module.exports = encontrarElementoRepetido; \ No newline at end of file diff --git a/C7 Arrays/ejercicios/31.js b/C7 Arrays/ejercicios/31.js index e75dcb7773..a12e41727b 100644 --- a/C7 Arrays/ejercicios/31.js +++ b/C7 Arrays/ejercicios/31.js @@ -2,6 +2,11 @@ function invertirTexto(texto) { // La función recibe un argumento "texto" que es un string. // Tu objetivo es invertir el string y devolver el string invertido. // Tu código: + let textoSeparado = texto.split(""); + textoSeparado = textoSeparado.reverse(); + textoSeparado = textoSeparado.join(""); + return textoSeparado; + } module.exports = invertirTexto; diff --git a/C7 Arrays/ejercicios/32.js b/C7 Arrays/ejercicios/32.js index 6e46790cd2..ede2040e1b 100644 --- a/C7 Arrays/ejercicios/32.js +++ b/C7 Arrays/ejercicios/32.js @@ -5,6 +5,15 @@ function esPalindromo(string) { // IMPORTANTE: Un palíndromo es una palabra o frase // que se lee igual hacia adelante que hacia atrás. // Tu código: + let stringInverso = string.split(""); + stringInverso = stringInverso.reverse(); + stringInverso = stringInverso.join(""); + for (let i = 0; i < string.length; i++) { + if(string[i] !== stringInverso[i]){ + return false; + } + } + return true; } module.exports = esPalindromo; \ No newline at end of file diff --git a/C7 Arrays/ejercicios/33.js b/C7 Arrays/ejercicios/33.js index defe758f76..7c0a6aa3cb 100644 --- a/C7 Arrays/ejercicios/33.js +++ b/C7 Arrays/ejercicios/33.js @@ -7,6 +7,27 @@ function combine(str1, str2, str3) { // combine("abc", "12345", "") == "a1b2c345" // combine("abc", "12345", "67") == "a16b27c345" // Tu código: + let suma = 0; + let newstr1 = [] + let newstr2 = [] + let newstr3 = [] + let stringCompleto = []; + if (str1.length !== 0){ + newstr1 = str1.split(""); + } + if (str2.length !== 0){ + newstr2 = str2.split(""); + } + if (str3.length !== 0){ + newstr3 = str3.split(""); + } + suma = str1.length + str2.length + str3.length; + for (let i = 0; i < suma; i++) { + stringCompleto.push(str1[i]); + stringCompleto.push(str2[i]); + stringCompleto.push(str3[i]); + } + return stringCompleto.join(""); } module.exports = combine; \ No newline at end of file diff --git a/C8 Objects + Callbacks/callbacks/ejercicios/01.js b/C8 Objects + Callbacks/callbacks/ejercicios/01.js index 9540c6b3b2..31ac63ebd0 100644 --- a/C8 Objects + Callbacks/callbacks/ejercicios/01.js +++ b/C8 Objects + Callbacks/callbacks/ejercicios/01.js @@ -2,6 +2,7 @@ function invocarCallback(cb) { // Invoca/ejecuta el callback `cb`. // NOTA: no debes retornar nada. // Tu código: + cb(); } module.exports = invocarCallback; diff --git a/C8 Objects + Callbacks/callbacks/ejercicios/02.js b/C8 Objects + Callbacks/callbacks/ejercicios/02.js index df7a401ef8..023bda5daa 100644 --- a/C8 Objects + Callbacks/callbacks/ejercicios/02.js +++ b/C8 Objects + Callbacks/callbacks/ejercicios/02.js @@ -3,6 +3,10 @@ function cambiarCadena(string, callback) { // La función de callback se encargará de recibir el string y devolverlo con los cambios. // Si no se recibe una función callback entonces se debe retornar el string original. // Tu código: + if (typeof callback !== "function"){ + return string; + } + return callback(string); } module.exports = cambiarCadena; diff --git a/C8 Objects + Callbacks/callbacks/ejercicios/03.js b/C8 Objects + Callbacks/callbacks/ejercicios/03.js index 767f0a1808..a426711b78 100644 --- a/C8 Objects + Callbacks/callbacks/ejercicios/03.js +++ b/C8 Objects + Callbacks/callbacks/ejercicios/03.js @@ -3,6 +3,8 @@ function operacionMatematica(num1, num2, cb) { // El callback realiza una operación matemática, por lo que necesita de los dos números. // Retorna el resultado del callback pasándole por valores los números num1 y num2. // Tu código: + const devuelveCB = cb(num1, num2); + return devuelveCB; } module.exports = operacionMatematica; diff --git a/C8 Objects + Callbacks/callbacks/ejercicios/04.js b/C8 Objects + Callbacks/callbacks/ejercicios/04.js index 04f18b1ec5..7bfbb74ba4 100644 --- a/C8 Objects + Callbacks/callbacks/ejercicios/04.js +++ b/C8 Objects + Callbacks/callbacks/ejercicios/04.js @@ -4,6 +4,11 @@ function sumarArray(arrayOfNumbers, cb) { // Este resultado debes pasárselo como argumento al callback recibido. // NOTA: no debes retornar nada. // Tu código: + let suma = 0; + for (let i = 0; i < arrayOfNumbers.length; i++) { + suma += arrayOfNumbers[i]; + } + cb(suma); } module.exports = sumarArray; diff --git a/C8 Objects + Callbacks/callbacks/ejercicios/05.js b/C8 Objects + Callbacks/callbacks/ejercicios/05.js index cecc94504d..4a8b9a32b1 100644 --- a/C8 Objects + Callbacks/callbacks/ejercicios/05.js +++ b/C8 Objects + Callbacks/callbacks/ejercicios/05.js @@ -2,6 +2,9 @@ function forEach(array, cb) { // Recibes un arreglo y un callback. // Itera sobre el arreglo y por cada elemento iterado, ejecuta el callback con este valor. // Tu código: + for (let i = 0; i < array.length; i++) { + cb(array[i]); + } } module.exports = forEach; diff --git a/C8 Objects + Callbacks/callbacks/ejercicios/06.js b/C8 Objects + Callbacks/callbacks/ejercicios/06.js index e09a7bf8c4..4473200e1a 100644 --- a/C8 Objects + Callbacks/callbacks/ejercicios/06.js +++ b/C8 Objects + Callbacks/callbacks/ejercicios/06.js @@ -3,6 +3,8 @@ function map(array, cb) { // Tiene que guardar el resultado devuelto por el callback en cada elemento dentro de un nuevo arreglo. // Retorna el nuevo arreglo. // Tu código: + let arrayNew = array.map((elemento) => { return cb(elemento)}) + return arrayNew; } module.exports = map; diff --git a/C8 Objects + Callbacks/callbacks/ejercicios/07.js b/C8 Objects + Callbacks/callbacks/ejercicios/07.js index d9983d4528..758f9b16a6 100644 --- a/C8 Objects + Callbacks/callbacks/ejercicios/07.js +++ b/C8 Objects + Callbacks/callbacks/ejercicios/07.js @@ -2,6 +2,8 @@ function filter(arrayOfStrings) { // Debes identificar todos los elementos el arreglo que comiencen con la letra "a". // Luego retorna un nuevo arreglo con estos elementos. // Tu código: + let comienzaA = arrayOfStrings.filter( (palabra) => palabra.at(0) == "a") + return comienzaA; } module.exports = filter; diff --git a/C8 Objects + Callbacks/callbacks/ejercicios/08.js b/C8 Objects + Callbacks/callbacks/ejercicios/08.js index b4c2cad28a..d7d4c79b7f 100644 --- a/C8 Objects + Callbacks/callbacks/ejercicios/08.js +++ b/C8 Objects + Callbacks/callbacks/ejercicios/08.js @@ -3,6 +3,17 @@ const buscarElemento = (array, callback) => { // Si el elemento no se encuentra, devuelve el mensje "No se encontró el elemento". // La función de callback es la encargada de evaluar si el elemento fue encontrado. // Tu código: + /*let elementoEncontrado = callback(array); + if (elementoEncontrado.length === 0 || Object.keys(elementoEncontrado) === 0){ + return "No se encontró el elemento" + }; + return elementoEncontrado;*/ + for (let i = 0; i < array.length; i++) { + if (callback(array[i])){ + return array[i]; + } + } + return "No se encontró el elemento"; }; module.exports = buscarElemento; diff --git a/C8 Objects + Callbacks/objects/ejercicios/01.js b/C8 Objects + Callbacks/objects/ejercicios/01.js index 4e28b4c584..5bc3b72675 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/01.js +++ b/C8 Objects + Callbacks/objects/ejercicios/01.js @@ -2,8 +2,8 @@ const obtenerValorPropiedad = (objeto, propiedad) => { // Recibe un objeto y el nombre de una propiedad. // Devuelve el valor de esta propiedad. // Tu código: - const a = objeto[propiedad]; - + //let a = objeto.propiedad > funciona, pero el ejercicio pide bracket notation. + const a = objeto[propiedad]; return a; }; diff --git a/C8 Objects + Callbacks/objects/ejercicios/03.js b/C8 Objects + Callbacks/objects/ejercicios/03.js index 9705c17350..76ef426aa0 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/03.js +++ b/C8 Objects + Callbacks/objects/ejercicios/03.js @@ -1,6 +1,8 @@ const agregarNuevaPropiedad = (objeto, propiedad, valor) => { // Añade una nueva propiedad al objeto con su respectivo valor pasado por la función. // Tu código: + objeto[propiedad] = valor; + return objeto; }; module.exports = agregarNuevaPropiedad; diff --git a/C8 Objects + Callbacks/objects/ejercicios/04.js b/C8 Objects + Callbacks/objects/ejercicios/04.js index 8dbc773948..c7a676d29b 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/04.js +++ b/C8 Objects + Callbacks/objects/ejercicios/04.js @@ -3,6 +3,10 @@ function verificarPropiedad(objeto, propiedad) { // Retorna true si la tiene, sino retorna false. // PISTA: puedes usar el método hasOwnProperty(). // Tu código: + if(objeto.hasOwnProperty(propiedad)){ + return true; + } + return false; } module.exports = verificarPropiedad; diff --git a/C8 Objects + Callbacks/objects/ejercicios/05.js b/C8 Objects + Callbacks/objects/ejercicios/05.js index 57485922a9..f5d8d21b41 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/05.js +++ b/C8 Objects + Callbacks/objects/ejercicios/05.js @@ -2,6 +2,8 @@ const listarPropiedades = (objeto) => { // Lista y retorna todas las propiedades que posee el objeto recibido por la función. // PISTA: Puedes usar el método Object.keys(). // Tu código: + let propiedades = Object.keys(objeto); + return propiedades; }; module.exports = listarPropiedades; diff --git a/C8 Objects + Callbacks/objects/ejercicios/06.js b/C8 Objects + Callbacks/objects/ejercicios/06.js index da96759653..2d186bb017 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/06.js +++ b/C8 Objects + Callbacks/objects/ejercicios/06.js @@ -2,6 +2,14 @@ const contarPropiedades = (objeto) => { // Cuenta y retorna el total de propiedades que tiene el objeto. // PISTA: Puedes iterarlo usando el bucle for-in. // Tu código: + /* let propiedades = Object.keys(objeto); + return propiedades.length;*/ + // LA Forma en la que lo pide el enunciado; + let suma = 0; + for (const key in objeto) { + suma++ + } + return suma; }; module.exports = contarPropiedades; diff --git a/C8 Objects + Callbacks/objects/ejercicios/07.js b/C8 Objects + Callbacks/objects/ejercicios/07.js index 38b33c7db6..86677bace1 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/07.js +++ b/C8 Objects + Callbacks/objects/ejercicios/07.js @@ -7,6 +7,7 @@ function sort(sortBy, list) { // recibes --> ("a", [{ a: 1, b: 3 }, { a: 3, b: 2 }, { a: 2, b: 40 }]) // retorna --> [{ a: 3, b: 2 }, { a: 2, b: 40 }, { a: 1, b: 3 }] // Tu código: + return list.sort((a, b) => b[sortBy] - a[sortBy]); } module.exports = sort; diff --git a/C8 Objects + Callbacks/objects/ejercicios/08.js b/C8 Objects + Callbacks/objects/ejercicios/08.js index b6915259c4..24832f61ea 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/08.js +++ b/C8 Objects + Callbacks/objects/ejercicios/08.js @@ -5,6 +5,14 @@ function crearGato(nombre, edad) { // La propiedad "meow" será una función que retorne el string: "Meow!". // Retornar el objeto. // Tu código: -} + let newObject = { + nombre: nombre, + edad: edad, + meow: function() { + return "Meow!" + } + } + return newObject; +}; module.exports = crearGato; diff --git a/C8 Objects + Callbacks/objects/ejercicios/09.js b/C8 Objects + Callbacks/objects/ejercicios/09.js index ff0b379077..6896b333ed 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/09.js +++ b/C8 Objects + Callbacks/objects/ejercicios/09.js @@ -3,6 +3,12 @@ function nuevoUsuario(nombre, email, password) { // Este debe tener las propiedades: "nombre", "email" y "password" con sus respectivos valores. // Retorna el objeto creado. // Tu código: + let usuario = { + nombre: nombre, + email: email, + password: password, + }; + return usuario; } module.exports = nuevoUsuario; diff --git a/C8 Objects + Callbacks/objects/ejercicios/10.js b/C8 Objects + Callbacks/objects/ejercicios/10.js index b307e660e3..7ee88e8adb 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/10.js +++ b/C8 Objects + Callbacks/objects/ejercicios/10.js @@ -4,6 +4,8 @@ function agregarPropiedad(objeto, propiedad) { // Esta propiedad será igual al valor `null`. // Retornar el objeto. // Tu código: + objeto[propiedad] = null; + return objeto; } module.exports = agregarPropiedad; diff --git a/C8 Objects + Callbacks/objects/ejercicios/11.js b/C8 Objects + Callbacks/objects/ejercicios/11.js index 85579d0d92..f25bcf2ebf 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/11.js +++ b/C8 Objects + Callbacks/objects/ejercicios/11.js @@ -3,6 +3,7 @@ function invocarMetodo(objeto, metodo) { // Esta propiedad contiene una función en su interior. Debes invocarla/ejecutarla. // NOTA: no necesitas retornar nada. // Tu código: + objeto[metodo](); } module.exports = invocarMetodo; diff --git a/C8 Objects + Callbacks/objects/ejercicios/12.js b/C8 Objects + Callbacks/objects/ejercicios/12.js index 976cd317d3..d6412442d9 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/12.js +++ b/C8 Objects + Callbacks/objects/ejercicios/12.js @@ -2,6 +2,8 @@ function multiplicarNumeroDesconocidoPorCinco(objetoMisterioso) { // El parámetro "objetoMisterioso" posee una propiedad con el nombre "numeroMisterioso". // Debes multiplicar este número por 5 y retornar el resultado. // Tu código: + let num = objetoMisterioso.numeroMisterioso * 5; + return num; } module.exports = multiplicarNumeroDesconocidoPorCinco; diff --git a/C8 Objects + Callbacks/objects/ejercicios/13.js b/C8 Objects + Callbacks/objects/ejercicios/13.js index 26b71ad81e..ef11a01bd3 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/13.js +++ b/C8 Objects + Callbacks/objects/ejercicios/13.js @@ -2,6 +2,8 @@ function eliminarPropiedad(objeto, propiedad) { // El parámetro "propiedad" es una propiedad del objeto que recibes. // Debes eliminarla del objeto y retornarlo finalmente. // Tu código: + delete objeto[propiedad]; + return objeto; } module.exports = eliminarPropiedad; diff --git a/C8 Objects + Callbacks/objects/ejercicios/14.js b/C8 Objects + Callbacks/objects/ejercicios/14.js index 21b96699d2..69c8dccc01 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/14.js +++ b/C8 Objects + Callbacks/objects/ejercicios/14.js @@ -2,6 +2,10 @@ function tieneEmail(objetoUsuario) { // Verifica si el "objetoUsuario", en su propiedad "email", posee un valor definido. // En ese caso, retorna true. Caso contrario, false. // Tu código: + if(objetoUsuario.email == undefined){ + return false + } + return true; } module.exports = tieneEmail; diff --git a/C8 Objects + Callbacks/objects/ejercicios/15.js b/C8 Objects + Callbacks/objects/ejercicios/15.js index 9fe787b8fb..bc8f63fad7 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/15.js +++ b/C8 Objects + Callbacks/objects/ejercicios/15.js @@ -2,6 +2,10 @@ function tienePropiedad(objeto, propiedad) { // Verifica si el objeto recibido posee una propiedad con el mismo nombre que el parámetro "propiedad". // En ese caso, retorna true. Caso contrario, false. // Tu código: + if(objeto.hasOwnProperty([propiedad])){ + return true; + } + return false; } module.exports = tienePropiedad; diff --git a/C8 Objects + Callbacks/objects/ejercicios/16.js b/C8 Objects + Callbacks/objects/ejercicios/16.js index 27c5dd2f47..2349375acd 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/16.js +++ b/C8 Objects + Callbacks/objects/ejercicios/16.js @@ -2,6 +2,10 @@ function verificarPassword(objetoUsuario, password) { // Verifica si la propiedad "password" del "objetoUsuario" coincide con el parámetro "password". // En ese caso, retorna true. Caso contrario, false. // Tu código: + if(objetoUsuario.password == password){ + return true; + } + return false; } module.exports = verificarPassword; diff --git a/C8 Objects + Callbacks/objects/ejercicios/17.js b/C8 Objects + Callbacks/objects/ejercicios/17.js index acdbae5590..097013daaa 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/17.js +++ b/C8 Objects + Callbacks/objects/ejercicios/17.js @@ -3,6 +3,8 @@ function actualizarPassword(objetoUsuario, nuevaPassword) { // La nueva contraseña la recibes por parámetro. // Retornar el objeto. // Tu código: + objetoUsuario.password = nuevaPassword; + return objetoUsuario; } module.exports = actualizarPassword; diff --git a/C8 Objects + Callbacks/objects/ejercicios/18.js b/C8 Objects + Callbacks/objects/ejercicios/18.js index 1af064c1bf..2d9f5d5f6b 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/18.js +++ b/C8 Objects + Callbacks/objects/ejercicios/18.js @@ -3,6 +3,8 @@ function agregarAmigo(objetoUsuario, nuevoAmigo) { // Debes agregar el "nuevoAmigo" al final de este arreglo. // Retornar el objeto. // Tu código: + objetoUsuario.amigos.push(nuevoAmigo); + return objetoUsuario; } module.exports = agregarAmigo; diff --git a/C8 Objects + Callbacks/objects/ejercicios/19.js b/C8 Objects + Callbacks/objects/ejercicios/19.js index ccf3d4db4f..94609fd9ec 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/19.js +++ b/C8 Objects + Callbacks/objects/ejercicios/19.js @@ -4,6 +4,10 @@ function pasarUsuarioAPremium(objetoMuchosUsuarios) { // Define esta propiedad de todos los usuarios como true. // Retornar el arreglo. // Tu código: + for (let i = 0; i < objetoMuchosUsuarios.length; i++) { + objetoMuchosUsuarios[i].esPremium = true; + } + return objetoMuchosUsuarios; } module.exports = pasarUsuarioAPremium; diff --git a/C8 Objects + Callbacks/objects/ejercicios/20.js b/C8 Objects + Callbacks/objects/ejercicios/20.js index b2ed3cce78..3881a90fcf 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/20.js +++ b/C8 Objects + Callbacks/objects/ejercicios/20.js @@ -4,6 +4,11 @@ function sumarLikesDeUsuario(objetoUsuario) { // Cada post posee una propiedad llamada "likes". Esta propiedad es un número. // Debes sumar los likes de todos los post y retornar el resultado. // Tu código: + let mg = 0; + for (let i = 0; i < objetoUsuario.posts.length; i++) { + mg += objetoUsuario.posts[i].likes; + } + return mg; } module.exports = sumarLikesDeUsuario; diff --git a/C8 Objects + Callbacks/objects/ejercicios/21.js b/C8 Objects + Callbacks/objects/ejercicios/21.js index 6533392cef..25228396ae 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/21.js +++ b/C8 Objects + Callbacks/objects/ejercicios/21.js @@ -9,6 +9,10 @@ function agregarMetodoCalculoDescuento(objetoProducto) { // PorcentajeDeDescuento ---> 0.2 // Precio final ---> 8 // Tu código: + objetoProducto.calcularPrecioDescuento = function() { + return this.precio-(this.precio * this.porcentajeDeDescuento) + } + return objetoProducto; } module.exports = agregarMetodoCalculoDescuento; diff --git a/C8 Objects + Callbacks/objects/ejercicios/22.js b/C8 Objects + Callbacks/objects/ejercicios/22.js index f14b686ac4..7c612e47b9 100644 --- a/C8 Objects + Callbacks/objects/ejercicios/22.js +++ b/C8 Objects + Callbacks/objects/ejercicios/22.js @@ -5,6 +5,11 @@ function esAnagrama(str1, str2) { // IMPORTANTE: Un anagrama es una palabra que se forma // con las mismas letras que otra, pero en orden diferente. // Tu código: + if (str1.length !== str2.length) return false; + + const ordenar = (str) => str.toLowerCase().split('').sort().join(''); + + return ordenar(str1) === ordenar(str2); } module.exports = esAnagrama; diff --git a/C9 Ejercicios Extra/Ejercicios Extra.js b/C9 Ejercicios Extra/Ejercicios Extra.js index d921ce5d0d..ef5d9f6a81 100644 --- a/C9 Ejercicios Extra/Ejercicios Extra.js +++ b/C9 Ejercicios Extra/Ejercicios Extra.js @@ -6,6 +6,8 @@ function deObjetoAarray(objeto) { // Estos elementos debe ser cada par clave:valor del objeto recibido. // [EJEMPLO]: {D: 1, B: 2, C: 3} ---> [['D', 1], ['B', 2], ['C', 3]]. // Tu código: + let array = Object.entries(objeto); + return array; } function numberOfCharacters(string) { @@ -14,6 +16,18 @@ function numberOfCharacters(string) { // Las letras deben estar en orden alfabético. // [EJEMPLO]: "adsjfdsfsfjsdjfhacabcsbajda" ---> { a: 5, b: 2, c: 2, d: 4, f: 4, h:1, j: 4, s: 5 } // Tu código: + let letra = 1; + let letrasContadas = {}; + let newString = string.split('').sort().join(''); + for (let i = 0; i < newString.length; i++) { + if(newString[i] == newString[i+1]){ + letra++ + }else{ + letrasContadas[newString[i]]=letra; + letra = 1; + } + } + return letrasContadas } function capToFront(string) { @@ -22,6 +36,17 @@ function capToFront(string) { // Retornar el string. // [EJEMPLO]: soyHENRY ---> HENRYsoy // Tu código: + let mayus = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + let str1 = []; + let str2 = []; + for (let i = 0; i < string.length; i++) { + if(mayus.includes(string[i])){ + str1.push(string[i]) + } else { + str2.push(string[i]) + } + } + return str1.join("")+str2.join(""); } function asAmirror(frase) { @@ -29,18 +54,39 @@ function asAmirror(frase) { // La diferencia es que cada palabra estará escrita al inverso. // [EJEMPLO]: "The Henry Challenge is close!" ---> "ehT yrneH egnellahC si !esolc" // Tu código: + let frase1 = frase.split(" "); + let fraseAlreves = []; + for (let i = 0; i < frase1.length; i++) { + frase = frase1[i].split("").reverse().join(""); + fraseAlreves.push(frase); + } + return fraseAlreves.join(" "); } function capicua(numero) { // Si el número que recibes es capicúa debes retornar el string: "Es capicua". // Caso contrario: "No es capicua". // Tu código: + let numeroAlReves = numero.toString().split("").reverse().join(""); + if(numero == numeroAlReves){ + return "Es capicua"; + } + return "No es capicua"; } function deleteAbc(string) { // Tu tarea es eliminar las letras "a", "b" y "c" del string recibido. // Retorna el string sin estas letras. // Tu código: + string = string.split(""); + let sinABC = []; + for (let i = 0; i < string.length; i++) { + if(string[i] == "a" || string[i] == "b" || string[i] == "c"){ + continue; + } + sinABC.push(string[i]); + } + return sinABC.join(""); } function sortArray(arrayOfStrings) { @@ -49,6 +95,15 @@ function sortArray(arrayOfStrings) { // de la longitud de cada string. // [EJEMPLO]: ["You", "are", "beautiful", "looking"] ---> [“You", "are", "looking", "beautiful"] // Tu código: + /*let largo = []; + let palabras = []; + for (let i = 0; i < arrayOfStrings.length; i++) { + largo.push(arrayOfStrings[i].length); + } + for (let i = 0; i < arrayOfStrings.length; i++) { + + }*/ + return arrayOfStrings.sort((word1, word2) => word1.length - word2.length) } function buscoInterseccion(array1, array2) { @@ -58,6 +113,15 @@ function buscoInterseccion(array1, array2) { // Si no tienen elementos en común, retornar un arreglo vacío. // [PISTA]: los arreglos no necesariamente tienen la misma longitud. // Tu código: + let arrayFinal = []; + for (let i = 0; i < array1.length; i++) { + for (let j = 0; j < array2.length; j++) { + if(array1[i]==array2[j]){ + arrayFinal.push(array1[i]) + } + } + } + return arrayFinal; } /*⚠️ NO MODIFIQUES NADA DEBAJO DE ESTO ⚠️*/