From 5d51b7a60424c42c76094e0b87574a249475412e Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sat, 26 Feb 2022 23:10:51 +0100 Subject: [PATCH 01/11] feat: ejercicios 1, 2, 3, 4 hechos --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index e69de29..58b4bce 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,14 @@ + +//1 +const arrayVacio = [] + +//2 +const arrayNumeros = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + +//3 +const arrayNumerosPares = [ 0, 2, 4, 6, 8] + +//4 +const arrayBidimensional = [[ 0, 1, 2], [ 'a', 'b', 'c']] + +//5 From e07ae121ed8bf082195e5c4421857d2287c42d85 Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sat, 26 Feb 2022 23:17:01 +0100 Subject: [PATCH 02/11] feat: ejercicio 5 hecho --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 58b4bce..25b7f22 100644 --- a/index.js +++ b/index.js @@ -11,4 +11,10 @@ const arrayNumerosPares = [ 0, 2, 4, 6, 8] //4 const arrayBidimensional = [[ 0, 1, 2], [ 'a', 'b', 'c']] + //5 +function suma ( a, b) { + return a + b +} + +//6 From a863542b39b650edf7bb6fd6e4069877afaf19fb Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sat, 26 Feb 2022 23:18:02 +0100 Subject: [PATCH 03/11] feat: ejercicio 6 hecho --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 25b7f22..24aa5df 100644 --- a/index.js +++ b/index.js @@ -18,3 +18,8 @@ function suma ( a, b) { } //6 +function potenciacion ( a, b) { + return a ** b +} + +//7 From 83425a707c3b6e250b44e375282cae1b32c8a5ba Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sat, 26 Feb 2022 23:59:19 +0100 Subject: [PATCH 04/11] feat: ejercicios 7, 8, 9 hechos --- index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/index.js b/index.js index 24aa5df..9c688ec 100644 --- a/index.js +++ b/index.js @@ -23,3 +23,23 @@ function potenciacion ( a, b) { } //7 +function separarPalabras (string) { + return string.split(' ') +} + +//8 +function repetirString (string, number) { + return string.repeat(number) +} + +//9 +function esPrimo (number) { + for (let i = 2; i < number; i++) { + if (number % i === 0) { + return false + } + } + return true +} + +//10 From e02c37f553556dfdec4dcb3454495d791a237efa Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sun, 27 Feb 2022 02:38:35 +0100 Subject: [PATCH 05/11] feat: ejercicios 10 y 11 --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index 9c688ec..369c13c 100644 --- a/index.js +++ b/index.js @@ -42,4 +42,20 @@ function esPrimo (number) { return true } + //10 +function ordenarArray ( array) { + return array.sort() +} + +//11 +function obtenerPares( array) { + let newArray = [] + for (let i = 0; i < array.length; i++) { + if (array [i] % 2 === 0) + newArray.push(array[i]) + } + return newArray +} + +// \ No newline at end of file From 49de26a9b4fd48a1dcd362263b7ddb08ac418040 Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sun, 27 Feb 2022 02:56:50 +0100 Subject: [PATCH 06/11] feat: ejercicio 13 --- index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 369c13c..48f4d06 100644 --- a/index.js +++ b/index.js @@ -58,4 +58,19 @@ function obtenerPares( array) { return newArray } -// \ No newline at end of file +//12 no va +/* function pintarArray (array) { + return '['+array.toString()+']' +} */ + +//13 +function arrayMapi (array, fArray) { + let newArray = [] + for (let i = 0; i < array.length; i++) { + fArray(array[i]) + newArray.push(fArray(array[i])) + + } + return newArray +} + From c1672d0061ff5cd8f001fcb0e0f9db59e6a6122f Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sun, 27 Feb 2022 03:15:42 +0100 Subject: [PATCH 07/11] feat: ejercicio 14 --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 48f4d06..96a16c9 100644 --- a/index.js +++ b/index.js @@ -74,3 +74,8 @@ function arrayMapi (array, fArray) { return newArray } +//14 +function eliminarDuplicados(array) { + return [...new Set(array)] + +} \ No newline at end of file From 80cecdff721e3e5bc7c274ec2566ed9a5b0299cc Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sun, 27 Feb 2022 03:38:14 +0100 Subject: [PATCH 08/11] feat: ejercicios 15, 16, 17, 18 --- index.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 96a16c9..e9ee1fa 100644 --- a/index.js +++ b/index.js @@ -74,8 +74,21 @@ function arrayMapi (array, fArray) { return newArray } -//14 +//14 al crear una instancia con nuestro array, se eliminan todos los repetidos function eliminarDuplicados(array) { return [...new Set(array)] - -} \ No newline at end of file +} + +//15 +const arrayNumerosNeg = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] + +//16 +const holaMundo = ['Hola', 'Mundo'] + +//17 +const loGuardoTodo = ['hola', 'que', 23, 42.33, 'tal'] + +//18 +const arrayDeArrays = [[756, 'nombre'], [225, 'apellido'], [298, 'direccion']] + +//19 From 962807bdaa04a4b358803ae232e13a70d1f4cbf1 Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sun, 27 Feb 2022 03:55:13 +0100 Subject: [PATCH 09/11] feat: ejercicios 19, 20, 21, 22 --- index.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/index.js b/index.js index e9ee1fa..5eedf90 100644 --- a/index.js +++ b/index.js @@ -79,6 +79,7 @@ function eliminarDuplicados(array) { return [...new Set(array)] } + //15 const arrayNumerosNeg = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] @@ -91,4 +92,33 @@ const loGuardoTodo = ['hola', 'que', 23, 42.33, 'tal'] //18 const arrayDeArrays = [[756, 'nombre'], [225, 'apellido'], [298, 'direccion']] + //19 +function multiplicacion (a, b) { + return a * b +} + +//20 +function division (a, b) { + return a / b +} + +//21 +function esPar (a) { + if (a % 2 === 0) { + return true + } + return false +} + +//22 +const arrayFunciones = [ + function suma(a, b) { + return a + b + }, + function resta(a, b) { + return a - b + }, + function multiplicacion(a, b) { + return a * b + }] From 071e15b01fc5393252dcb42b37285a5d1a148f90 Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sun, 27 Feb 2022 04:40:06 +0100 Subject: [PATCH 10/11] feat: ejercicios 23, 24, 25, 26 --- index.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5eedf90..baf39b6 100644 --- a/index.js +++ b/index.js @@ -59,9 +59,32 @@ function obtenerPares( array) { } //12 no va -/* function pintarArray (array) { - return '['+array.toString()+']' -} */ +function pintarArray (array) { + let newString = '' + for (let i = 0; i < array.length; i++) { // por qué esto da una coma de más al final?? + if (i !== 0 && i < array.length){ + newString += ' ' + array[i].toString() + ',' + } else if (i === array.length) { + newString += array[i].toString() + } else { + newString += array[i].toString() + ',' + } + /* switch (i) { + case 0: + newString += array[i].toString() + ',' + break; + + case array.length: + newString += ' ' + array[i].toString() + break; + default: + newString += array[i].toString() + ',' + break; + } + */ + } + return '['+newString.slice (0, -1)+']' +} //13 function arrayMapi (array, fArray) { @@ -122,3 +145,39 @@ const arrayFunciones = [ function multiplicacion(a, b) { return a * b }] + + +//23 +function ordenarArray2 (array) { + return array.sort() +} + +//24 +function obtenerImpares(array) { + let newArray = [] + for (let i = 0; i < array.length; i++) { + if (array[i] % 2 !== 0) { + newArray.push(array[i]) + } + } + return newArray +} + +//25 +function sumarArray (array) { + let suma = 0 + for (let i = 0; i < array.length; i++) { + suma += array [i] + } + return suma +} + +//26 +function multiplicarArray (array) { + let multiplicacion = 1 + for (let i = 0; i < array.length; i++) { + multiplicacion *= array [i] + + } + return multiplicacion +} \ No newline at end of file From 50a074a531540ad9047642f3fd4f236b9f171ed3 Mon Sep 17 00:00:00 2001 From: Brujitari Date: Sun, 27 Feb 2022 17:25:47 +0100 Subject: [PATCH 11/11] =?UTF-8?q?feat:=20ejercicio=2012=20mejorado,=20no?= =?UTF-8?q?=20iba=20porque=20la=20=C3=BAltima=20i=20!=3D=3D=20array.lenght?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index baf39b6..dc486f4 100644 --- a/index.js +++ b/index.js @@ -61,29 +61,16 @@ function obtenerPares( array) { //12 no va function pintarArray (array) { let newString = '' - for (let i = 0; i < array.length; i++) { // por qué esto da una coma de más al final?? - if (i !== 0 && i < array.length){ + for (let i = 0; i < array.length; i++) { + if (i !== 0 && (i+1) < array.length){ //elements in between newString += ' ' + array[i].toString() + ',' - } else if (i === array.length) { - newString += array[i].toString() - } else { - newString += array[i].toString() + ',' + } else if ((i+1) === array.length) { //last element + newString += ' ' + array[i].toString() +']' + } else { //first element + newString += '['+ array[i].toString() + ',' } - /* switch (i) { - case 0: - newString += array[i].toString() + ',' - break; - - case array.length: - newString += ' ' + array[i].toString() - break; - default: - newString += array[i].toString() + ',' - break; - } - */ } - return '['+newString.slice (0, -1)+']' + return newString } //13