diff --git a/exercises/07.2-Letter-Counter/README.es.md b/exercises/07.2-Letter-Counter/README.es.md index a17472f5..538c73f2 100644 --- a/exercises/07.2-Letter-Counter/README.es.md +++ b/exercises/07.2-Letter-Counter/README.es.md @@ -1,8 +1,8 @@ -# `07.2` Contador de letras +# `07.2` Letter Counter Nuestro cliente necesita un programa que cuente las repeticiones de las letras en un string dado. Sé que es extraño, pero es muy testarudo ¡Lo necesitamos lo antes posible! -## :pencil: Instrucciones: +## 📝 Instrucciones: 1. Crea un objeto donde las letras son las propiedades y los valores son el número de veces que esa letra se repite en toda la cadena. @@ -14,7 +14,7 @@ const word = "Hello World"; // Debería imprimir en la consola { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 } ``` -## :bulb: Pista: +## 💡 Pistas: + Recorre todo el string (usa un bucle). diff --git a/exercises/07.2-Letter-Counter/README.md b/exercises/07.2-Letter-Counter/README.md index 0dad6dc9..2bd769ca 100644 --- a/exercises/07.2-Letter-Counter/README.md +++ b/exercises/07.2-Letter-Counter/README.md @@ -1,14 +1,12 @@ --- - tutorial: https://www.youtube.com/watch?v=oLTidCuisew - --- # `07.2` Letter Counter -Our customer needs a program that counts the number of occurences of each letter in a given string. I know that's weird, but they are very adamant. We need this asap! +Our customer needs a program that counts the number of occurrences of each letter in a given string. I know that's weird, but they are very adamant. We need this asap! -## :pencil: Instructions: +## 📝 Instructions: 1. Create an object where the letters are the properties and the values are the number of times that letter is repeated throughout the string. @@ -20,16 +18,16 @@ const word = "Hello World"; // The console should print { h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1 } ``` -## :bulb: Hint +## 💡 Hints: + Loop the entire string. -+ On every iteration check if the object `counts` has the letter initialized as a property. ++ On every iteration, check if the object `counts` has the letter initialized as a property. + If the letter has not been initialized, then do it and set its value equal to 1 (first time found). -+ If it was already initialized just increment the property value by one. ++ If it was already initialized, just increment the property value by one. + Remember to ignore white spaces in the string. -+ You should lower case all letters to have an accurate count of all letters regardless of casing of the letter. ++ To accurately count all letters, regardless of their casing, you should convert all letters to lowercase. diff --git a/exercises/07.2-Letter-Counter/app.js b/exercises/07.2-Letter-Counter/app.js index ea913651..c2557ef2 100644 --- a/exercises/07.2-Letter-Counter/app.js +++ b/exercises/07.2-Letter-Counter/app.js @@ -1,6 +1,6 @@ let par = "Lorem ipsum dolor sit amet consectetur adipiscing elit Curabitur eget bibendum turpis Curabitur scelerisque eros ultricies venenatis mi at tempor nisl Integer tincidunt accumsan cursus" let counts = {}; -// your code here +// Your code here -console.log(counts); \ No newline at end of file +console.log(counts); diff --git a/exercises/07.2-Letter-Counter/solution.hide.js b/exercises/07.2-Letter-Counter/solution.hide.js index 2662a35b..5a5b65f2 100644 --- a/exercises/07.2-Letter-Counter/solution.hide.js +++ b/exercises/07.2-Letter-Counter/solution.hide.js @@ -1,20 +1,16 @@ let par = "Lorem ipsum dolor sit amet consectetur adipiscing elit Curabitur eget bibendum turpis Curabitur scelerisque eros ultricies venenatis mi at tempor nisl Integer tincidunt accumsan cursus" let counts = {}; -// your code here -for(let i in par){ +// Your code here +for(let i in par) { const letter = par[i].toLowerCase(); - console.log(letter); if(letter == " ") continue; - else if(counts[letter] == undefined){ - console.log("Found "+letter+" for the first time") + else if(counts[letter] == undefined) { counts[letter] = 1; } - else{ - console.log("Found "+letter+" more than once") + else { counts[letter] = counts[letter] + 1; - } } -console.log(counts); \ No newline at end of file +console.log(counts); diff --git a/exercises/07.2-Letter-Counter/tests.js b/exercises/07.2-Letter-Counter/tests.js index 902caad6..8ca80817 100644 --- a/exercises/07.2-Letter-Counter/tests.js +++ b/exercises/07.2-Letter-Counter/tests.js @@ -13,7 +13,7 @@ it('You have to use the console.log function once, at the end of the exercise', expect(console.log.mock.calls.length).toBe(1); }); -it('Use a for loop', function () { +it('Use a "for" loop', function () { const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); expect(app_content).toMatch(/for(\s*)\(/); }); @@ -37,4 +37,4 @@ it('Create the object with the letter counts like { a: 1, b: 4, ... }', function } expect(counts).toEqual(_counts); -}); \ No newline at end of file +}); diff --git a/exercises/07.3-Flip-Array/README.es.md b/exercises/07.3-Flip-Array/README.es.md index 900a0a16..f957c49c 100644 --- a/exercises/07.3-Flip-Array/README.es.md +++ b/exercises/07.3-Flip-Array/README.es.md @@ -1,18 +1,18 @@ -# `07.3` Invierte el Array +# `07.3` Flip Array -## :pencil: Instrucciones: +## 📝 Instrucciones: -1. Usando un bucle `for`, invierte el arreglo o array `arr` e imprime el nuevo arreglo o array en la consola. +1. Usando un bucle `for`, invierte el array `arr` e imprime el nuevo array en la consola. Por ejemplo: ```js - array inicial: [45, 67, 87, 23, 5, 32, 60]; array array final : [60, 32, 5 , 23, 87, 67, 45]; +Initial array: [45, 67, 87, 23, 5, 32, 60]; +Final array: [60, 32, 5, 23, 87, 67, 45]; ``` -## :bulb: Pista +## 💡 Pistas: + Debes recorrer todo el arreglo [desde el final hasta el principio](https://stackoverflow.com/questions/1340589/are-loops-really-faster-in-reverse). -+ En cada bucle, inserta todos los elementos (a -medida que avanza) en un nuevo array o arreglo, este será tu arreglo invertido. \ No newline at end of file ++ En cada bucle, inserta todos los elementos (a medida que avanza) en un nuevo array, este será tu arreglo invertido. ¿Qué otros métodos puedes usar además de `push()`? diff --git a/exercises/07.3-Flip-Array/README.md b/exercises/07.3-Flip-Array/README.md index 471a9b01..fadb0080 100644 --- a/exercises/07.3-Flip-Array/README.md +++ b/exercises/07.3-Flip-Array/README.md @@ -4,19 +4,19 @@ tutorial: https://www.youtube.com/watch?v=Snn7OtZY370 # `07.3` Flip Array -## :pencil: Instructions: +## 📝 Instructions: 1. Using a `for` loop, invert the `arr` array and print the new array on the console. For example: ```js -Initial array: [45, 67, 87, 23, 5, 32, 60]; -Final array: [60, 32, 5 , 23, 87, 67, 45]; +Initial array: [45, 67, 87, 23, 5, 32, 60]; +Final array: [60, 32, 5, 23, 87, 67, 45]; ``` -## :bulb: Hint +## 💡 Hints: -+ You should loop the entire array [from the end to the beggining](https://stackoverflow.com/questions/1340589/are-loops-really-faster-in-reverse). ++ You should loop the entire array [from the end to the beginning](https://stackoverflow.com/questions/1340589/are-loops-really-faster-in-reverse). -+ On each loop push all the items (as you go) into a new array, this will be your flipped array. What other methods can you use besides `push()`? ++ On each loop, push all the items (as you go) into a new array, this will be your flipped array. What other methods can you use besides `push()`? diff --git a/exercises/07.3-Flip-Array/app.js b/exercises/07.3-Flip-Array/app.js index 4876d9ad..6d1a63d4 100644 --- a/exercises/07.3-Flip-Array/app.js +++ b/exercises/07.3-Flip-Array/app.js @@ -1,3 +1,3 @@ let arr = [45,67,87,23,5,32,60]; -//Your code here. +// Your code here diff --git a/exercises/07.3-Flip-Array/solution.hide.js b/exercises/07.3-Flip-Array/solution.hide.js index 71a2b3b5..3ed2a36e 100644 --- a/exercises/07.3-Flip-Array/solution.hide.js +++ b/exercises/07.3-Flip-Array/solution.hide.js @@ -1,9 +1,10 @@ let arr = [45,67,87,23,5,32,60]; -//Your code here. +// Your code here let flippedArray = [] -for(let i = arr.length - 1; i>= 0;i--){ +for(let i = arr.length - 1; i >= 0; i--) { let item = arr[i]; flippedArray.push(item); } -console.log(flippedArray) \ No newline at end of file + +console.log(flippedArray) diff --git a/exercises/07.3-Flip-Array/tests.js b/exercises/07.3-Flip-Array/tests.js index 3eb7484b..706e506a 100644 --- a/exercises/07.3-Flip-Array/tests.js +++ b/exercises/07.3-Flip-Array/tests.js @@ -9,23 +9,18 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n"); let reverse = Array.prototype.reverse; Array.prototype.reverse = jest.fn(function(){ return this; }); -it('Use the console.log function once to print the new array with the types on the console', function () { +it('Use the console.log function once, at the end of the exercise', function () { const app = require('./app.js'); expect(console.log.mock.calls.length).toBe(1); }); -it("Use the typeof function inside the loop", function () { - const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); - expect(app_content).not.toMatch(/\.typeof/); -}); - -it('There needs to be a variable called arr with the original array', function () { +it('There needs to be a variable called "arr" with the original array', function () { const _app = rewire('./app.js'); const variable = _app.__get__('arr'); expect(variable).toBeTruthy(); }); -it('Loop the array in a reverse order and console.log all of its item', function () { +it('Loop the array in a reverse order and console.log all of its items', function () { const _app = rewire('./app.js'); const variable = _app.__get__('arr'); let inverted = []; @@ -33,4 +28,4 @@ it('Loop the array in a reverse order and console.log all of its item', function inverted.push(variable[i]); } expect(_buffer).toMatch(inverted.map(n => n).join(",")); -}); \ No newline at end of file +}); diff --git a/exercises/08.1-Mixed-array/README.es.md b/exercises/08.1-Mixed-array/README.es.md index d5bf7c79..3c909eae 100644 --- a/exercises/08.1-Mixed-array/README.es.md +++ b/exercises/08.1-Mixed-array/README.es.md @@ -1,10 +1,10 @@ -# `08.01` Array mixto +# `08.1` Mixed Array -## :pencil: Instrucciones: +## 📝 Instrucciones: -1. Escribe una función que imprima un arreglo en la consola que contenga los tipos de valores (data-types) que contiene el array `mix` en cada posición. +1. Usando un bucle, imprime un nuevo array en la consola que contenga los tipos de valores (data-types) que contiene el array `mix` en cada posición. -### Resultado esperado: +## 💻 Resultado esperado: ```js [ @@ -15,14 +15,14 @@ ] ``` -## :bulb: Pista +## 💡 Pista + Crea un nuevo arreglo vacío. + Recorre el arreglo original mediante un bucle. -+ En cada bucle, obten el tipo de elemento utilizando la función `typeof`. ++ En cada bucle, obtén el tipo de elemento utilizando la función `typeof`. -+ Como la función `typeof` devuelve un string, puedes insertar(push) ese string en el nuevo arreglo(array). ++ Como la función `typeof` devuelve un string, puedes insertar(push) ese string en el nuevo arreglo. -+ Cuando finalice el bucle o loop, debes haber encontrado todos los tipos de elementos del arreglo o array original y haberlos insertados(push) en el nuevo arreglo. \ No newline at end of file ++ Cuando finalice el bucle, debes haber encontrado todos los tipos de elementos del arreglo original y haberlos insertado(push) en el nuevo arreglo. diff --git a/exercises/08.1-Mixed-array/README.md b/exercises/08.1-Mixed-array/README.md index 40d77253..507109f1 100644 --- a/exercises/08.1-Mixed-array/README.md +++ b/exercises/08.1-Mixed-array/README.md @@ -2,13 +2,13 @@ tutorial: https://www.youtube.com/watch?v=3o02odJhieo --- -# `08.01` Mixed Array +# `08.1` Mixed Array -## :pencil: Instructions: +## 📝 Instructions: -1. Write a function that prints in the console a new array that contains all the types of data that the array `mix` contains in each position. +1. Using a loop, print in the console a new array that contains all the types of data that the array `mix` contains in each position. -### Expected Result: +## 💻 Expected Result: ```js [ @@ -19,14 +19,14 @@ tutorial: https://www.youtube.com/watch?v=3o02odJhieo ] ``` -## :bulb: Hints: +## 💡 Hints: + Create a new empty array. + Loop the original array. -+ On every loop get the type of the item using the `typeof` function. ++ On every loop, get the type of the item using the `typeof` function. -+ Since the `typeof` function return a string you can push that string to the new array. ++ Since the `typeof` function returns a string you can push that string to the new array. -+ when the loop finished, you should have all the types found on the original array pushed to the new array. \ No newline at end of file ++ When the loop is finished, you should have all the types found on the original array pushed to the new array. diff --git a/exercises/08.1-Mixed-array/app.js b/exercises/08.1-Mixed-array/app.js index fc215a43..15dcd2e8 100644 --- a/exercises/08.1-Mixed-array/app.js +++ b/exercises/08.1-Mixed-array/app.js @@ -1,3 +1,3 @@ let mix = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}]; -//your code here \ No newline at end of file +// Your code here diff --git a/exercises/08.1-Mixed-array/solution.hide.js b/exercises/08.1-Mixed-array/solution.hide.js index 87b987f3..fca7698b 100644 --- a/exercises/08.1-Mixed-array/solution.hide.js +++ b/exercises/08.1-Mixed-array/solution.hide.js @@ -1,10 +1,10 @@ let mix = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}]; -//your code here +// Your code here let newArray = []; for (let i = 0; i < mix.length; i++) { const item = mix[i]; newArray.push(typeof item) - } -console.log(newArray) \ No newline at end of file + +console.log(newArray) diff --git a/exercises/08.1-Mixed-array/tests.js b/exercises/08.1-Mixed-array/tests.js index f29a2263..83bcf353 100644 --- a/exercises/08.1-Mixed-array/tests.js +++ b/exercises/08.1-Mixed-array/tests.js @@ -14,17 +14,12 @@ it("Create a loop", function () { expect(app_content).toMatch(/for\s*/); }); -it("Don't use the reverse function", function () { - const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); - expect(app_content).not.toMatch(/\.reverse(\s*)\(/); -}); - it('Use the console.log function once to print the newArray on the console', function () { const app = require('./app.js'); expect(console.log.mock.calls.length).toBe(1); }); -it('There needs to be a variable called mix with the original array', function () { +it('There needs to be a variable called "mix" with the original array', function () { const _app = rewire('./app.js'); const variable = _app.__get__('mix'); expect(variable).toBeTruthy(); @@ -45,4 +40,4 @@ it('Loop the array and console.log all of its item types', function () { let _test = myFunc() expect(_buffer).toMatch(_test.map(n => n).join(",")); // expect(_buffer).toMatch(inverted.map(n => n).join(",")); -}); \ No newline at end of file +}); diff --git a/exercises/08.2-Count-On/README.es.md b/exercises/08.2-Count-On/README.es.md index c7a3f05f..4132c573 100644 --- a/exercises/08.2-Count-On/README.es.md +++ b/exercises/08.2-Count-On/README.es.md @@ -2,27 +2,29 @@ Como viste en el último ejercicio, tu arreglo o array puede tener una mezcla de tipos de datos. -## :pencil: Instrucciones +## 📝 Instrucciones: 1. Agrega todos los elementos con tipo de dato objeto dentro del array `hello`. -Aquí puedes ver cómo imprimir TODOS los elementos. +Aquí puedes ver cómo imprimir los tipos de elementos: ```js let myArray = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}]; -for(let index = 0; index < myArray.length; index++){ - let item = myArray[index]; +for(let i = 0; i < myArray.length; i++) { + let item = myArray[i]; console.log(typeof(item)) } ``` -## :bulb: Pista +> Nota: Te darás cuenta que cuando verificas el tipo de dato de un array, te devolverá que es un `'object'`. Puedes investigar el por qué en Google o proceder con el ejercicio como de costumbre. + +## 💡 Pistas: + Recorre el array dado con un loop. -+ Agrega una condición dentro del bucle(loop) que verifique que el elemento sea un objeto. ++ Agrega una condición dentro del bucle que verifique que el elemento sea un objeto. + Si el elemento es un objeto, se agrega al arreglo `hello`. -+ Usa `console.log()`para imprimir el array `hello` en la consola. ++ Usa `console.log()` para imprimir el array `hello` en la consola. diff --git a/exercises/08.2-Count-On/README.md b/exercises/08.2-Count-On/README.md index c86c66f8..5299782c 100644 --- a/exercises/08.2-Count-On/README.md +++ b/exercises/08.2-Count-On/README.md @@ -1,23 +1,25 @@ # `08.2` Count On -As you saw in the last exercise your array can be a mix of data types. +As you saw in the last exercise, your array can be a mix of data types. -## :pencil: Instructions: +## 📝 Instructions: 1. Add all the items with data type 'object' into the `hello` array. -Here is how to print all the items. +Here is how to print all the item types: ```js let myArray = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}]; -for(let index = 0; index < myArray.length; index++){ - let item = myArray[index]; +for(let i = 0; i < myArray.length; i++) { + let item = myArray[i]; console.log(typeof(item)) } ``` -## :bulb: Hint: +> Note: You may notice that when checking the type of an array, it outputs `'object'`. You can search about it on Google or proceed with the exercise normally. + +## 💡 Hints: + Loop the given array. diff --git a/exercises/08.2-Count-On/app.js b/exercises/08.2-Count-On/app.js index 30e7a6c5..7d75c74a 100644 --- a/exercises/08.2-Count-On/app.js +++ b/exercises/08.2-Count-On/app.js @@ -1,9 +1,9 @@ let myArray = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}]; let hello = []; -for(let index = 0; index < myArray.length; index++){ - let element = myArray[index]; +for(let i = 0; i < myArray.length; i++) { + let item = myArray[i]; // MAGIC HAPPENS HERE } -console.log(hello) \ No newline at end of file +console.log(hello) diff --git a/exercises/08.2-Count-On/solution.hide.js b/exercises/08.2-Count-On/solution.hide.js index 501331e5..8d21af58 100644 --- a/exercises/08.2-Count-On/solution.hide.js +++ b/exercises/08.2-Count-On/solution.hide.js @@ -1,7 +1,7 @@ let myArray = [42, true, "towel", [2,1], 'hello', 34.4, {"name": "juan"}]; let hello = []; -for(let i = 0; i < myArray.length; i++){ +for(let i = 0; i < myArray.length; i++) { let item = myArray[i]; // MAGIC HAPPENS HERE if (typeof item === 'object') { @@ -9,4 +9,4 @@ for(let i = 0; i < myArray.length; i++){ } } -console.log(hello) \ No newline at end of file +console.log(hello) diff --git a/exercises/08.2-Count-On/tests.js b/exercises/08.2-Count-On/tests.js index a5d571a2..92a1c28c 100644 --- a/exercises/08.2-Count-On/tests.js +++ b/exercises/08.2-Count-On/tests.js @@ -8,20 +8,20 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n"); const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); -it('Use the console.log function once to print the variable hello', function () { +it('Use the console.log function once to print the variable "hello"', function () { const app = require('./app.js'); expect(console.log.mock.calls.length).toBe(1); }); -it("Use a for loop", function () { +it('Use a "for" loop', function () { expect(app_content).toMatch(/for(\s*)\(/); }); -it("Use a condition 'if' statement only for items of type object", function () { +it('Use a conditional "if" statement only for items of type \'object\'', function () { expect(app_content).toMatch(/if(\s*)\(/); }); -it("Do not cheat using the function filter", function () { +it('Do not cheat using the function filter', function () { expect(app_content).not.toMatch(/\.filter(\s*)\(/); }); @@ -32,11 +32,11 @@ it("Do not cheat using the function filter", function () { // expect(variable.filter(item => typeof(item) === "object")).toMatch(hello); // }); -it('The new array "hello" should only contain the "objects" in myArray', function () { +it('The new array "hello" should only contain the \'object\' types in myArray', function () { const _app = rewire('./app.js'); const variable = _app.__get__('myArray'); const hello = _app.__get__('hello'); const elements = variable.filter(item => typeof(item) === 'object'); expect(hello).toEqual(elements); -}); \ No newline at end of file +}); diff --git a/exercises/08.3-Sum-all-items/README.es.md b/exercises/08.3-Sum-all-items/README.es.md index b8205bfa..ba12aff0 100644 --- a/exercises/08.3-Sum-all-items/README.es.md +++ b/exercises/08.3-Sum-all-items/README.es.md @@ -1,15 +1,17 @@ -# `08.3` Suma todos los elementos +# `08.3` Sum All Items -## :pencil: Instrucciones: +## 📝 Instrucciones: -1. Usando un bucle (loop) `for`, completa el código de la función `sumTheElements` para que devuelva la suma de todos los elementos en un arreglo (array) dado, por ejemplo: +1. Usando un bucle (loop) `for`, completa el código de la función `sumTheElements` para que devuelva la suma de todos los elementos en un array dado. + +## 💻 Resultado esperado: ```js console.log(sumTheElements([2,13,34,5])) -//el resultado debiese ser 54 +// El resultado debe ser 54 ``` -## :bulb: Pista: +## 💡 Pistas: + Inicializa una variable `total` en 0. @@ -19,8 +21,4 @@ console.log(sumTheElements([2,13,34,5])) + Devuelve la variable `total` (fuera del bucle pero dentro de la función). -### Resultado esperado: - -```js -54 -``` \ No newline at end of file ++ Llama la función con un arreglo cualquiera de números que sumados den el resultado esperado de arriba `54`. diff --git a/exercises/08.3-Sum-all-items/README.md b/exercises/08.3-Sum-all-items/README.md index 050a8268..f93fa8ec 100644 --- a/exercises/08.3-Sum-all-items/README.md +++ b/exercises/08.3-Sum-all-items/README.md @@ -1,18 +1,19 @@ # `08.3` Sum All Items -## :pencil: Instructions: +## 📝 Instructions: -Using a `for` loop, complete the code of the function `sumTheElements` so that it returns the sum of all the items in a given array, for example: +1. Using a `for` loop, complete the code of the function `sumTheElements` so that it returns the sum of all the items in a given array. + +## 💻 Expected result: ```js console.log(sumTheElements([2,13,34,5])) -//this should print 54 +// This should print 54 ``` -## :bulb: Hint: -+ Initialize a variable `total` at 0. +## 💡 Hints: -+ Call the function with any array of numbers that add up to the expected result above. ++ Initialize a variable `total` at 0. + Loop the entire array inside of the function. @@ -20,8 +21,4 @@ console.log(sumTheElements([2,13,34,5])) + Return the `total` variable (outside of the loop but inside of the function). -### Expected result: - -```js -54 -``` ++ Call the function with any array of numbers that add up to the expected result above `54`. diff --git a/exercises/08.3-Sum-all-items/app.js b/exercises/08.3-Sum-all-items/app.js index 3e25668e..ad2ffb38 100644 --- a/exercises/08.3-Sum-all-items/app.js +++ b/exercises/08.3-Sum-all-items/app.js @@ -1,6 +1,6 @@ -function sumTheElements(theArray){ +function sumTheElements(theArray) { let total = 0; - //your code here + // Your code here return total; -} \ No newline at end of file +} diff --git a/exercises/08.3-Sum-all-items/solution.hide.js b/exercises/08.3-Sum-all-items/solution.hide.js index 95155b05..8a0a756f 100644 --- a/exercises/08.3-Sum-all-items/solution.hide.js +++ b/exercises/08.3-Sum-all-items/solution.hide.js @@ -1,13 +1,12 @@ -function sumTheElements(sumArray){ +function sumTheElements(theArray) { - sumArray =[2,13,34,5] let total = 0; - - //your code here - for (let i = 0; i < sumArray.length; i++) { - - total += sumArray[i] + // Your code here + for (let i = 0; i < theArray.length; i++) { + total += theArray[i] } return total; -} \ No newline at end of file +} + +console.log(sumTheElements([2,13,34,5])) diff --git a/exercises/08.3-Sum-all-items/tests.js b/exercises/08.3-Sum-all-items/tests.js index 71dba1db..0deaa6ca 100644 --- a/exercises/08.3-Sum-all-items/tests.js +++ b/exercises/08.3-Sum-all-items/tests.js @@ -8,11 +8,11 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n"); const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); -it("Use a for loop", function () { +it('Use a "for" loop', function () { expect(app_content).toMatch(/for(\s*)\(/); }); -it("Do not cheat using the function .forEach", function () { +it('Do not cheat using the function .forEach', function () { expect(app_content).not.toMatch(/\.forEach(\s*)\(/); }); diff --git a/exercises/09-forEach-loop/README.es.md b/exercises/09-forEach-loop/README.es.md index 08c166a1..36203717 100644 --- a/exercises/09-forEach-loop/README.es.md +++ b/exercises/09-forEach-loop/README.es.md @@ -1,11 +1,11 @@ -# `09` Bucle/loop forEach +# `09` forEach Loop -En lugar de usar la clásica declaración `for`, hay una nueva forma de recorrer los arreglos: [ higher order functions (funciones de orden superior) ](https://www.youtube.com/watch?v=rRgD1yVwIvE) +En lugar de usar la clásica declaración `for`, hay una nueva forma de recorrer los arreglos: [higher order functions (funciones de orden superior)](https://www.youtube.com/watch?v=rRgD1yVwIvE). -Es posible recorrer un arreglo usando la función `array.forEach`. Debes especificar qué hacer en cada iteración del bucle. +Es posible recorrer un arreglo usando la función `myArray.forEach()`. Debes especificar qué hacer en cada iteración del bucle. ```js -myArray.forEach(function(item, index, arr){ +myArray.forEach(function(item, index, arr) { }); /** @@ -15,12 +15,12 @@ myArray.forEach(function(item, index, arr){ */ ``` -## :pencil: Instrucciones: +## 📝 Instrucciones: -En este momento, el código está imprimiendo todos los elementos en el arreglo o array: +En este momento, el código está imprimiendo todos los elementos en el array: 1. Cambia el código de la función para imprimir solo los números divisibles por 14. -## :bulb: Pista: +## 💡 Pista: -+ Un número X es divisible por 2 si `(X%2===0)`. \ No newline at end of file ++ Un número (x) es divisible por 2 si `(x % 2 === 0)`. diff --git a/exercises/09-forEach-loop/README.md b/exercises/09-forEach-loop/README.md index 5b7be44d..e3731023 100644 --- a/exercises/09-forEach-loop/README.md +++ b/exercises/09-forEach-loop/README.md @@ -1,28 +1,26 @@ # `09` forEach Loop -Instead of using the classic `for` statement, there is a new way to loop arrays called [higher order functions](https://www.youtube.com/watch?v=rRgD1yVwIvE). +Instead of using the classic `for` statement, there is a new way to loop arrays, called [higher order functions](https://www.youtube.com/watch?v=rRgD1yVwIvE). -It is possible to loop an array using the `array.forEach` function. You have to specify what to do on each iteration of the loop. +It is possible to loop an array using the `myArray.forEach()` function. You have to specify what to do on each iteration of the loop. ```js -myArray.forEach(function(item, index, arr){ +myArray.forEach(function(item, index, arr) { }); /** * item: will be the value of the specific item (required). - * index: will be the item index(optional). + * index: will be the item index (optional). * arr: will be the array object to which the element belongs to (optional). */ - - ``` -## :pencil: Instructions: +## 📝 Instructions: Right now, the code is printing all the items in the array: 1. Please change the function code to print only the numbers divisible by 14. -## :bulb: Hint: +## 💡 Hint: -A number X is divisible by 2 if: `(X%2===0)`. ++ A number (x) is divisible by 2 if: `(x % 2 === 0)`. diff --git a/exercises/09-forEach-loop/app.js b/exercises/09-forEach-loop/app.js index 51475751..18b3206d 100644 --- a/exercises/09-forEach-loop/app.js +++ b/exercises/09-forEach-loop/app.js @@ -1,6 +1,6 @@ let myArray = [3344,34334,454543,342534,4563456,3445,23455,234,262,2335,43323,4356,345,4545,452,345,434,36,345,4334,5454,345,4352,23,365,345,47,63,425,6578759,768,834,754,35,32,445,453456,56,7536867,3884526,4234,35353245,53244523,566785,7547,743,4324,523472634,26665,63432,54645,32,453625,7568,5669576,754,64356,542644,35,243,371,3251,351223,13231243,734,856,56,53,234342,56,545343]; -myArray.forEach(function(item, index, arr){ +myArray.forEach(function(item, index, arr) { // The value of the item is console.log(item); -}); \ No newline at end of file +}); diff --git a/exercises/09-forEach-loop/solution.hide.js b/exercises/09-forEach-loop/solution.hide.js index 4b5327ec..3a2b01a6 100644 --- a/exercises/09-forEach-loop/solution.hide.js +++ b/exercises/09-forEach-loop/solution.hide.js @@ -1,9 +1,8 @@ let myArray = [3344,34334,454543,342534,4563456,3445,23455,234,262,2335,43323,4356,345,4545,452,345,434,36,345,4334,5454,345,4352,23,365,345,47,63,425,6578759,768,834,754,35,32,445,453456,56,7536867,3884526,4234,35353245,53244523,566785,7547,743,4324,523472634,26665,63432,54645,32,453625,7568,5669576,754,64356,542644,35,243,371,3251,351223,13231243,734,856,56,53,234342,56,545343]; -myArray.forEach(function(item, index, arr){ +myArray.forEach(function(item, index, arr) { // The value of the item is if (item % 14 === 0) { console.log(item); } - -}); \ No newline at end of file +}); diff --git a/exercises/10-Everything-is-awesome/README.es.md b/exercises/10-Everything-is-awesome/README.es.md index a2dff015..c32d3020 100644 --- a/exercises/10-Everything-is-awesome/README.es.md +++ b/exercises/10-Everything-is-awesome/README.es.md @@ -1,13 +1,17 @@ -# `10` Todo es increíble +# `10` Everything is awesome ## 📝 Instrucciones: -1. Compara el elemento. Si es `1`, pon el número en el arreglo `return_array`. +1. Compara el elemento. Si es `1`, agrega el número en el arreglo `return_array`. -2. Compara el elemento. Si es `0`, pon `Yahoo` en el arreglo o array `return_array` (en lugar del número) +2. Compara el elemento. Si es `0`, agrega el string `'Yahoo'` en el arreglo `return_array` (en lugar del número). -Por ejemplo la salida de `[0,0,1,1,0]` sería: +Por ejemplo, la salida de `[0,0,1,1,0]` sería: ```js -['Yahoo','Yahoo','1','1','Yahoo'] +['Yahoo','Yahoo', 1, 1,'Yahoo'] ``` + +## 💡 Pista: + ++ Cuando agregues el número `1` al nuevo array, asegúrate de hacerlo como número y no como string. diff --git a/exercises/10-Everything-is-awesome/README.md b/exercises/10-Everything-is-awesome/README.md index c20f715f..e526a7da 100644 --- a/exercises/10-Everything-is-awesome/README.md +++ b/exercises/10-Everything-is-awesome/README.md @@ -2,12 +2,16 @@ ## 📝 Instructions: -1. Compare the item. If it is `1` push the number to the array `return_array`. +1. Compare the item. If it's `1` push the number to the array `return_array`. -2. Compare the item. If it is 0 push `Yahoo` to the array `return_array` (instead of the number) +2. Compare the item. If it's `0` push the string `'Yahoo'` to the array `return_array` (instead of the number). -For example for `[0,0,1,1,0]` the output would be: +For example, for `[0,0,1,1,0]` the output would be: ```js -['Yahoo','Yahoo','1','1','Yahoo'] +['Yahoo','Yahoo', 1, 1,'Yahoo'] ``` + +## 💡 Hint: + ++ When you push the number `1` to the new array, make sure you push it as a number and not as a string. diff --git a/exercises/10-Everything-is-awesome/app.js b/exercises/10-Everything-is-awesome/app.js index 11f447a4..cc761072 100644 --- a/exercises/10-Everything-is-awesome/app.js +++ b/exercises/10-Everything-is-awesome/app.js @@ -2,10 +2,10 @@ let myArray = [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 1 ]; const ZerosToYahoos = (arr) => { let return_array = []; - arr.forEach((item,index) => { + arr.forEach((item) => { // magic goes inside these brackets }); return return_array; }; -console.log(ZerosToYahoos(myArray)); \ No newline at end of file +console.log(ZerosToYahoos(myArray)); diff --git a/exercises/10-Everything-is-awesome/solution.hide.js b/exercises/10-Everything-is-awesome/solution.hide.js index d242f48f..4a547bac 100644 --- a/exercises/10-Everything-is-awesome/solution.hide.js +++ b/exercises/10-Everything-is-awesome/solution.hide.js @@ -4,10 +4,9 @@ let myArray = [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 1 ]; const ZerosToYahoos = (arr) => { let return_array = []; - arr.forEach((item,index) => { + arr.forEach((item) => { // magic goes inside these brackets return_array.push(item === 1 ? item : 'Yahoo') - }); return return_array; }; @@ -20,17 +19,15 @@ let myArray2 = [ 1, 0, 0, 0, 1, 0, 0, 0, 1, 1 ]; const ZerosToYahoos2 = (arr) => { let return_array = []; - arr.forEach((item,index) => { + arr.forEach((item) => { // magic goes inside these brackets if (item === 1) { return_array.push(item) - }else{ + } else { return_array.push('Yahoo') - } - }); return return_array; }; -console.log(ZerosToYahoos2(myArray2)); \ No newline at end of file +console.log(ZerosToYahoos2(myArray2)); diff --git a/exercises/11-Do-while/README.es.md b/exercises/11-Do-while/README.es.md index d18b1a19..4bd58473 100644 --- a/exercises/11-Do-while/README.es.md +++ b/exercises/11-Do-while/README.es.md @@ -1,9 +1,9 @@ # `11` DO DO DO -El `do{}while()`; es otro ejemplo de bucle(loop) en javascript que se usa con menos frecuencia pero es un bucle. +El `do{}while()`; es otra declaracion de bucle en JavaScript que se usa con menos frecuencia, pero es un bucle. ```js -// declarando el valor para el loop o bucle: +// declarando el valor inicial para el loop: let i = 0; // el loop hará todo dentro del bloque de código @@ -18,11 +18,13 @@ do { ## 📝 Instrucciones: -1. Imprime cada número de la iteración en la consola del 20 al 0, pero concaténale un signo de exclamación(`!`) al elemento si el número es un múltiplo de 5. +1. Imprime cada número de la iteración en la consola del 20 al 0. -2. Al final haz un `console.log()`de `LIFTOFF` +2. Si el número es un múltiplo de 5, concaténale un signo de exclamación `!` al elemento. -### Resultado esperado: +3. Cuando el bucle llegue a cero, imprime `LIFTOFF` en vez del número `0`. Esta instrucción debe ir también dentro del bucle. + +## 💻 Resultado esperado: ```js 20! @@ -38,5 +40,6 @@ do { 10! . . +1 LIFTOFF ``` diff --git a/exercises/11-Do-while/README.md b/exercises/11-Do-while/README.md index 6fbfc838..0d74fef2 100644 --- a/exercises/11-Do-while/README.md +++ b/exercises/11-Do-while/README.md @@ -1,9 +1,9 @@ # `11` DO DO DO -The `do{}while()`; is another loop example in javascript is less commonly used but it is a loop. +The `do{}while()`; is another loop statement in JavaScript that is less commonly used, but it's still a loop. ```js -// stating value for the loop: +// starting value for the loop: let i = 0; // the loop will do everything inside of the do code block @@ -20,12 +20,11 @@ do { 1. Print every iteration number on the console from 20 to 0. -2. Print the numbers that are module of 5 with a concatenated exclamation mark. +2. Print the numbers that are module of 5 with a concatenated exclamation mark `!`. 3. When the loop reaches zero, print `LIFTOFF` instead of `0`. This `console.log()` statement must go **inside** of the loop. - -### Expected result: +## 💻 Expected result: ```js 20! diff --git a/exercises/11-Do-while/app.js b/exercises/11-Do-while/app.js index 0db3f713..d14baa15 100644 --- a/exercises/11-Do-while/app.js +++ b/exercises/11-Do-while/app.js @@ -1,7 +1,7 @@ let i = 20; do { - // Magic goes here; + // Magic goes here i--; -} while (i > 0); \ No newline at end of file +} while (i >= 0); diff --git a/exercises/11-Do-while/solution.hide.js b/exercises/11-Do-while/solution.hide.js index 96107a23..813b9c44 100644 --- a/exercises/11-Do-while/solution.hide.js +++ b/exercises/11-Do-while/solution.hide.js @@ -1,12 +1,13 @@ let i = 20; do { - // Magic goes here; - if (i % 5 === 0) { - console.log(i + "!") - // console.log(i+"!") + // Magic goes here + if (i === 0) { + console.log("LIFTOFF"); + } else if (i % 5 === 0) { + console.log(i + "!"); + } else { + console.log(i); } - else { console.log(i) } i--; -} while (i > 0); -console.log("LIFTOFF") \ No newline at end of file +} while (i >= 0); diff --git a/exercises/11-Do-while/test.js b/exercises/11-Do-while/test.js index fc9653fd..058cc6bc 100644 --- a/exercises/11-Do-while/test.js +++ b/exercises/11-Do-while/test.js @@ -8,13 +8,13 @@ global.console.log = console.log = jest.fn((text) => _buffer += text + "\n"); const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); -test('You have to use the do-while function', () => { +test('You have to use the do...while function', () => { const file = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); const regex = /do\s*/gm expect(regex.test(file.toString())).toBeTruthy(); }) -it("The output should match the one in the instructions", function () { +it('The output should match the one in the instructions', function () { const app = require('./app.js'); let _output = []; diff --git a/exercises/12-Delete-element/README.es.md b/exercises/12-Delete-element/README.es.md index edfdb35c..74a5889b 100644 --- a/exercises/12-Delete-element/README.es.md +++ b/exercises/12-Delete-element/README.es.md @@ -1,16 +1,16 @@ -# `12` Eliminar el elemento +# `12` Delete element -La única forma de eliminar a `Daniella` del array o arreglo (sin hacer trampa) es crear un nuevo arreglo con todas las demás personas, excepto `Daniella`. +La única forma de eliminar a `Daniella` del array (sin hacer trampa) es crear un nuevo array con todas las demás personas, excepto `Daniella`. Así se comporta el método `array.filter()`. Similar a los métodos `array.forEach()` y `array.map()`, es una función de orden superior, lo que significa que llama a otra función para lograr sus objetivos. -Esa funcion **callback** (de retorno) se llama `array.filter()` que acepta hasta 3 parámetros (opcionales) y el valor devuelto solo puede ser una cosa - una condición: +Esa función secundaria es llamada por `array.filter()` que acepta hasta 3 parámetros (opcionales) y el valor devuelto solo puede ser una cosa - una condición: ```js (elementBeingIterated, indexOfThatElement, theIteratedArray) => condition; ``` -Asi que si quieres quedarte solo con los números 2 y 4 del array o arreglo de números, tu método `array.filter()` se vería de esta forma: +Así que si quieres quedarte solo con los números 2 y 4 del array de números, tu método `array.filter()` se vería de esta forma: ```js let array = [2, 9, 5, 6, 4, 1, 2, 3, 4]; @@ -19,18 +19,18 @@ let newArray = array.filter((element) => element === 2 || element === 4); console.log(newArray); // resultado es [2, 4, 2, 4] ``` -El método `array.filter()` automáticamente crea un nuevo array o arreglo (`newArray`) en el cual solo están los elementos que cumplan con la condición. El resto de los elements quedan fuera del `newArray`. +El método `array.filter()` automáticamente crea un nuevo array en el cual solo están los elementos que cumplan con la condición. El resto de los elementos quedan fuera del `newArray`. -Puedes aprender más sobre este método [aquí](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) +Puedes aprender más sobre este método [aquí](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). -## 📝Instrucciones: +## 📝 Instrucciones: 1. Crea una función `deletePerson` que "elimine" a cualquier persona del arreglo y devuelva un nuevo arreglo sin esa persona. -## Resultado esperado: +## 💻 Resultado esperado: ```js - ['juan', 'ana', 'michelle', 'stefany', 'lucy', 'barak'] -['ana', 'michelle', 'daniella', 'stefany', 'lucy', 'barak'] +['juan', 'ana', 'michelle', 'stefany', 'lucy', 'barak', 'emilio'] +['ana', 'michelle', 'daniella', 'stefany', 'lucy', 'barak', 'emilio'] ['juan', 'ana', 'michelle', 'daniella', 'stefany', 'lucy', 'barak'] ``` diff --git a/exercises/12-Delete-element/README.md b/exercises/12-Delete-element/README.md index f27fa6a0..7748e43a 100644 --- a/exercises/12-Delete-element/README.md +++ b/exercises/12-Delete-element/README.md @@ -2,9 +2,9 @@ One of the ways to delete `Daniella` from the array (without cheating) will be to create a new list with all the other people but `Daniella`. -That happens to be the default behavior of the `array.filter()` method which you should know. Similar to the `array.forEach()` and `array.map()` methods, it is a higher-order function, which means that it calls another function to achieve its goals. +That happens to be the default behavior of the `array.filter()` method, which you should know. Similar to the `array.forEach()` and `array.map()` methods, it is a higher-order function, which means that it calls another function to achieve its goals. -That secondary **callback** function is called by the `array.filter()` with up to three parameters (which are optional) and the returned value can only be one thing - a condition: +That secondary **callback** function is called by the `array.filter()` with up to three parameters (which are optional), and the returned value can only be one thing - a condition: ```js (elementBeingIterated, indexOfThatElement, theIteratedArray) => condition; @@ -21,14 +21,13 @@ console.log(newArray); // outcome is [2, 4, 2, 4] The `array.filter()` method automatically creates a new array in which only the elements that pass the condition are kept. Any other elements are dropped from the `newArray`. -You can learn more about this method [here](https://www.w3schools.com/jsref/jsref_filter.asp) +You can learn more about this method [here](https://www.w3schools.com/jsref/jsref_filter.asp). -## Instructions: +## 📝 Instructions: 1. Please create a `deletePerson` function that "deletes" any given person from an array and returns a new array without that person. - -## Expected result: +## 💻 Expected result: ```js ['juan', 'ana', 'michelle', 'stefany', 'lucy', 'barak', 'emilio'] diff --git a/exercises/12-Delete-element/app.js b/exercises/12-Delete-element/app.js index 1bdb10ab..d267b379 100644 --- a/exercises/12-Delete-element/app.js +++ b/exercises/12-Delete-element/app.js @@ -1,6 +1,6 @@ let people = ['juan','ana','michelle','daniella','stefany','lucy','barak', 'emilio']; -//your code below +// Your code below console.log(deletePerson('daniella')); console.log(deletePerson('juan')); diff --git a/exercises/12-Delete-element/solution.hide.js b/exercises/12-Delete-element/solution.hide.js index 2a7c812d..77feb614 100644 --- a/exercises/12-Delete-element/solution.hide.js +++ b/exercises/12-Delete-element/solution.hide.js @@ -1,10 +1,11 @@ let people = ['juan','ana','michelle','daniella','stefany','lucy','barak', 'emilio']; -//your code below -function deletePerson(name){ +// Your code below +function deletePerson(name) { let peopleArray = people.filter((person) => person != name) return peopleArray } + console.log(deletePerson('daniella')); console.log(deletePerson('juan')); -console.log(deletePerson('emilio')); \ No newline at end of file +console.log(deletePerson('emilio')); diff --git a/exercises/12-Delete-element/test.js b/exercises/12-Delete-element/test.js index 8daa4997..13ae5e5b 100644 --- a/exercises/12-Delete-element/test.js +++ b/exercises/12-Delete-element/test.js @@ -15,17 +15,19 @@ test('The array "people" should exist', () => { const file = rewire("./app.js"); const people = file.__get__("people"); expect(people).not.toBe(undefined); -}) +}); + test('"daniella" should exist in the "people" array', () => { const file = rewire("./app.js"); const people = file.__get__("people"); expect(people[3]).toBe('daniella'); -}) +}); + test('"juan" should exist in the "people" array', () => { const file = rewire("./app.js"); const people = file.__get__("people"); expect(people[0]).toBe('juan'); -}) +}); test("Function deletePerson should exist", function () { expect(deletePerson).toBeTruthy(); @@ -34,22 +36,24 @@ test("Function deletePerson should exist", function () { test("Function deletePerson should return something", function () { expect(deletePerson()).not.toBe(undefined) }); + test('console.log() function should have been called 3 times', function () { //then I import the index.js (which should have the alert() call inside) const file = require("./app.js"); expect(console.log.mock.calls.length).toBe(3); }); -test("If you call the deletePerson function with the name daniella, she cannot appear in the new list.", function () { +test("If you call the deletePerson function with the name daniella, she cannot appear in the new list", function () { // expect(console.log).toHaveBeenCalledWith(deletePerson('daniella')) expect(deletePerson('daniella')).not.toContain('daniella'); }); -test("If you call the deletePerson function with the name juan, he cannot appear in the new list.", function () { + +test("If you call the deletePerson function with the name juan, he cannot appear in the new list", function () { // expect(console.log).toHaveBeenCalledWith(deletePerson('juan')) expect(deletePerson('juan')).not.toContain('juan'); }); -test("If you call the deletePerson function with the name emilio, he cannot appear in the new list.", function () { +test("If you call the deletePerson function with the name emilio, he cannot appear in the new list", function () { // expect(console.log).toHaveBeenCalledWith(deletePerson('emilio')) expect(deletePerson('emilio')).not.toContain('emilio'); }); diff --git a/exercises/13-Merge-arrays/README.es.md b/exercises/13-Merge-arrays/README.es.md index 23a34338..2d71886c 100644 --- a/exercises/13-Merge-arrays/README.es.md +++ b/exercises/13-Merge-arrays/README.es.md @@ -1,17 +1,22 @@ -# `13` Uniendo arrays: +# `13` Merging arrays -En este ejercicio vamos a combinar dos arreglos programaticamente. +En este ejercicio vamos a unir dos arreglos programáticamente. -## 📝Instrucciones: +## 📝 Instrucciones: -Escribe una función que combine dos arreglos y retorne un único arreglo nuevo que combine todos los valores de ambos arreglos en un solo arreglo. +1. Escribe una función que combine dos arrays y retorne un único array nuevo, con todos los elementos de ambos arrays. +2. Asegúrate de no crear un array con 2 arrays anidados. Debe ser un solo array con todos los nombres en su orden original. -### 💡 Pista: - -+ Tendrás que recorrer cada arreglo e insertar sus elementos en un nuevo arreglo. - -### Resultado esperado: +## 💻 Resultado esperado: ```js - ['Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell', 'Lucas', 'Jake', 'Scott', 'Amy', 'Molly', 'Hannah', 'Lucas'] +['Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell', 'Lucas', 'Jake', 'Scott', 'Amy', 'Molly', 'Hannah', 'Lucas'] ``` + +## 💡 Pistas: + ++ Puedes encontrar más información sobre diferentes formas de unir arrays [aquí](https://www.techiedelight.com/es/merge-elements-two-arrays-javascript/). + ++ Si tienes dificultades para evitar obtener un array anidado, echa un vistazo al concepto del [operador de propagación de JavaScript](https://www.educative.io/edpresso/what-is-the-spread-operator-in-javascript). + ++ Tendrás que recorrer cada arreglo e insertar sus elementos en un nuevo arreglo. diff --git a/exercises/13-Merge-arrays/README.md b/exercises/13-Merge-arrays/README.md index 300b349c..529b9d46 100644 --- a/exercises/13-Merge-arrays/README.md +++ b/exercises/13-Merge-arrays/README.md @@ -1,28 +1,23 @@ -# `13` Merging arrays: +# `13` Merging arrays +In this exercise we will learn how to merge two arrays. -In this exercise we will learn how to combine two arrays. - - -## 📝Instructions: +## 📝 Instructions: 1. Write a function that merges and returns the two arrays into a single new array, with all the items from both arrays inside. 2. Be sure not to create an array with two nested arrays. It should be a single array with all the names in their original order. -3. Find out why you souldn't use the `.push()` method? -## 💡 Hint: - -+ You will have to loop through each array and insert their items into a new array. - -## Expected result: +## 💻 Expected result: ```js - ['Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell', 'Lucas', 'Jake', 'Scott', 'Amy', 'Molly', 'Hannah', 'Lucas'] +['Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell', 'Lucas', 'Jake', 'Scott', 'Amy', 'Molly', 'Hannah', 'Lucas'] ``` -### 💡 Hint: +## 💡 Hints: + ++ You can find more information on the different ways to merge arrays [here](https://dmitripavlutin.com/javascript-merge-arrays/). -+ You can find more information on the different ways to merge arrays [here](https://dmitripavlutin.com/javascript-merge-arrays/) ++ If you are struggling with preventing getting a nested array, take a look at the concept of the JS [spread operator](https://www.educative.io/edpresso/what-is-the-spread-operator-in-javascript). -+ If you are struggling with preventing getting a nested array, take a look at the concept of the JS [spread operator](https://www.educative.io/edpresso/what-is-the-spread-operator-in-javascript) ++ You will have to loop through each array and insert their items into a new array. diff --git a/exercises/13-Merge-arrays/app.js b/exercises/13-Merge-arrays/app.js index cffbcdd4..47227125 100644 --- a/exercises/13-Merge-arrays/app.js +++ b/exercises/13-Merge-arrays/app.js @@ -1,10 +1,10 @@ -let chunk_one = [ 'Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell' ]; -let chunk_two = [ 'Lucas' , 'Jake','Scott','Amy', 'Molly','Hannah','Lucas']; +let chunkOne = [ 'Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell' ]; +let chunkTwo = [ 'Lucas', 'Jake', 'Scott', 'Amy', 'Molly', 'Hannah', 'Lucas' ]; const mergeArrays = (firstArray, secondArray) => { let newArray = [] - //your code here + // Your code here return newArray } -console.log(mergeArrays(chunk_one, chunk_two)); \ No newline at end of file +console.log(mergeArrays(chunkOne, chunkTwo)); diff --git a/exercises/13-Merge-arrays/solution.hide.js b/exercises/13-Merge-arrays/solution.hide.js index fdc16b4a..25bf8258 100644 --- a/exercises/13-Merge-arrays/solution.hide.js +++ b/exercises/13-Merge-arrays/solution.hide.js @@ -1,21 +1,21 @@ -let chunk_one = [ 'Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell' ]; -let chunk_two = [ 'Lucas' , 'Jake','Scott','Amy', 'Molly','Hannah','Lucas']; +let chunkOne = [ 'Lebron', 'Aaliyah', 'Diamond', 'Dominique', 'Aliyah', 'Jazmin', 'Darnell' ]; +let chunkTwo = [ 'Lucas', 'Jake', 'Scott', 'Amy', 'Molly', 'Hannah', 'Lucas' ]; const mergeArrays = (firstArray, secondArray) => { - // this array with contain items from both original arrays + // This array will contain items from both original arrays let newArray = [] - // loop the first array and add each item to newArray + // Loop the first array and push each item to newArray firstArray.forEach(item => { newArray.push(item) }) - // loop the SECOND array and add each item to newArray + // Loop the second array and push each item to newArray secondArray.forEach(item => { newArray.push(item) }) - //return merged array + // return merged array return newArray } -console.log(mergeArrays(chunk_one, chunk_two)); \ No newline at end of file +console.log(mergeArrays(chunkOne, chunkTwo)); diff --git a/exercises/13-Merge-arrays/test.js b/exercises/13-Merge-arrays/test.js index 145b33eb..55746fd0 100644 --- a/exercises/13-Merge-arrays/test.js +++ b/exercises/13-Merge-arrays/test.js @@ -13,7 +13,7 @@ test("Function mergeArrays should exist", function(){ const mergeArrays = file.__get__('mergeArrays'); expect(mergeArrays).toBeTruthy(); }); -it('The returned array must contain everything item from firstArray', function () { +it('The returned array must contain every item from firstArray', function () { const _app = rewire('./app.js'); const mergeArrays = _app.__get__('mergeArrays'); @@ -22,7 +22,7 @@ it('The returned array must contain everything item from firstArray', function ( const arrTest = mergeArrays(_chunk_one,_chunk_two); expect(arrTest).toEqual(expect.arrayContaining(_chunk_one)); }); -it('The returned array must contain everything item from secondArray', function () { +it('The returned array must contain every item from secondArray', function () { const _app = rewire('./app.js'); const mergeArrays = _app.__get__('mergeArrays'); diff --git a/exercises/14-Divide-and-Conquer/README.es.md b/exercises/14-Divide-and-Conquer/README.es.md index fc47e7dc..c7777ae4 100644 --- a/exercises/14-Divide-and-Conquer/README.es.md +++ b/exercises/14-Divide-and-Conquer/README.es.md @@ -1,20 +1,20 @@ -# `14` Divide y conquista +# `14` Divide and conquer ## 📝 Instrucciones: 1. Crea una función llamada `mergeTwoList` que reciba un arreglo de números (enteros). -2. Recorre el arreglo y separa los números pares e impares en diferentes arreglos. +2. Recorre el arreglo y separa los números **pares** e **impares** en diferentes arreglos. 3. Si el número es impar, envíalo a un arreglo denominado `odd`. 4. Si el número es par, envíalo a un arreglo denominado `even`. -5. Luego concatena el arreglo `odd` al arreglo `even` para combinarlos. +5. La función debe retornar un nuevo arreglo que contenga los elementos de ambos arreglos `odd` y `even` en ese orden. > Recuerda que el arreglo `odd` va primero y luego debes agregar los items del arreglo `even` usando el método `.concat()`. -Ejemplo: +Por ejemplo: ```js mergeTwoList([1,2,33,10,20,4]); @@ -23,6 +23,6 @@ mergeTwoList([1,2,33,10,20,4]); [1, 33, 2, 10, 20, 4] ``` -### 💡 Pista: +## 💡 Pista: -+ Crea variables vacías cuando necesites almacenar datos. \ No newline at end of file ++ Crea variables vacías o ***auxiliares*** cuando necesites almacenar datos dentro de una función. diff --git a/exercises/14-Divide-and-Conquer/README.md b/exercises/14-Divide-and-Conquer/README.md index c54db69e..8e15fa69 100644 --- a/exercises/14-Divide-and-Conquer/README.md +++ b/exercises/14-Divide-and-Conquer/README.md @@ -4,25 +4,25 @@ 1. Create a function called `mergeTwoList` that expects an array of numbers (integers). -2. Loop through the array and separate the odd and the even numbers in different arrays. +2. Loop through the array and separate the **odd** and the **even** numbers in different arrays. -3. If the number is odd number push it to a placeholder array named `odd`. +3. If the number is odd, push it to a placeholder array named `odd`. -4. If the number is even number push it to a placeholder array named `even`. +4. If the number is even, push it to a placeholder array named `even`. -5. The function should return a new array that contains both odd and even elements. +5. The function should return a new array that contains both `odd` and `even` elements in that order. + > Remember, the `odd` array comes first and you have to append the `even` array to it. Use the `.concat()` method. - -Example: +For example: ```js -mergeTwoList([1,2,33,10,20,4]) +mergeTwoList([1,2,33,10,20,4]); -// expected console output +// expected console output: [1, 33, 2, 10, 20, 4] ``` -### 💡 Hint: +## 💡 Hint: -+ Create local empty ***placeholder*** or ***auxiliary*** variables when you need to store data in a function. ++ Create local empty ***placeholders*** or ***auxiliary*** variables when you need to store data in a function. diff --git a/exercises/14-Divide-and-Conquer/app.js b/exercises/14-Divide-and-Conquer/app.js index 82615a19..c9ebb4a4 100644 --- a/exercises/14-Divide-and-Conquer/app.js +++ b/exercises/14-Divide-and-Conquer/app.js @@ -1,3 +1,3 @@ -let list_of_numbers = [4, 80, 85, 59, 37,25, 5, 64, 66, 81,20, 64, 41, 22, 76,76, 55, 96, 2, 68]; +let listOfNumbers = [4, 80, 85, 59, 37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68]; -// your code here +// Your code here diff --git a/exercises/14-Divide-and-Conquer/solution.hide.js b/exercises/14-Divide-and-Conquer/solution.hide.js index d43e19e4..040ae8cd 100644 --- a/exercises/14-Divide-and-Conquer/solution.hide.js +++ b/exercises/14-Divide-and-Conquer/solution.hide.js @@ -1,13 +1,17 @@ -let list_of_numbers = [4, 80, 85, 59, 37,25, 5, 64, 66, 81,20, 64, 41, 22, 76,76, 55, 96, 2, 68]; +let listOfNumbers = [4, 80, 85, 59, 37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68]; -// your code here -function mergeTwoList(array){ - let odd = [] - let even = [] +// Your code here +function mergeTwoList(array) { + let odd = []; + let even = []; for (let i = 0; i < array.length; i++) { - array[i] % 2 == 0 ? even.push(array[i]) : odd.push(array[i]) + if (array[i] % 2 === 0) { + even.push(array[i]); + } else { + odd.push(array[i]); + } } - - return odd.concat(even) -} \ No newline at end of file + + return odd.concat(even); +} diff --git a/exercises/14-Divide-and-Conquer/test.js b/exercises/14-Divide-and-Conquer/test.js index 26605dfe..8e8e1bb7 100644 --- a/exercises/14-Divide-and-Conquer/test.js +++ b/exercises/14-Divide-and-Conquer/test.js @@ -19,7 +19,7 @@ test('You have to use a "for" loop', () => { const regex = /for\s*/gm expect(regex.test(file.toString())).toBeTruthy(); }) -test('You have to use a "for" loop', () => { +test('You must use the .concat() method', () => { const file = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); const regex = /.concat\s*/gm expect(regex.test(file.toString())).toBeTruthy(); @@ -63,4 +63,4 @@ test('The returned array must contain inside all the even items at the end', () _evens_1.forEach((num, i) => expect(num).toEqual(arrTest_1[i + 8])) _evens_2.forEach((num, i) => expect(num).toEqual(arrTest_2[i + 5])) -}); \ No newline at end of file +});