Skip to content

Commit b442390

Browse files
authored
Merge pull request #139 from josemoracard/jose6-20.4-Map-data-types
2 parents bab53d3 + 6ff7381 commit b442390

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+369
-228
lines changed
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
# `20.4` `Map` y tipos de datos
2-
3-
Algunas veces los arreglos vienen con valores mixtos y debes unificarlos en un solo tipo de datos.
1+
# `20.4` Map data types
42

53
## 📝 Instrucciones:
64

7-
1. Actualiza la función `array.map()` para que cree un nuevo arreglo que contenga los tipos de datos de cada elemento correspondiente al arreglo original.
5+
1. Modifica la función de `array.map()` para que cree un nuevo arreglo que contenga los tipos de datos de cada elemento del arreglo dado.
86

97
## 💡 Pista:
108

11-
+ Usa la función `typeof` para obtener el tipo de datos
9+
+ Usa la función `typeof` para obtener el tipo de dato.
1210

13-
## Resultado esperado:
11+
## 💻 Resultado esperado:
1412

1513
```js
16-
[string,string,... ,number,string,...]
14+
[
15+
'string', 'string',
16+
'string', 'string',
17+
'string', 'string',
18+
'number', 'number'
19+
]
1720
```

exercises/20.4-Map-data-types/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# `20.4` Map data types
22

3-
Some times arrays come with mixed values and you need to unify them into only one data type.
4-
53
## 📝 Instructions:
64

7-
1. Update the `array.map()` function to make it create a new array that contains the data types of each corresponding item from the original array.
5+
1. Update the `array.map()` function to make it create a new array that contains the data types of each item from the given array.
86

97
## 💡 Hint:
108

119
+ Use the `typeof` function to get the data type.
12-
## Expected result:
10+
11+
## 💻 Expected result:
1312

1413
```js
15-
[string,string,... ,number,string,...]
14+
[
15+
'string', 'string',
16+
'string', 'string',
17+
'string', 'string',
18+
'number', 'number'
19+
]
1620
```
17-

exercises/20.4-Map-data-types/app.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
let mixedDataTypes = ['1', '5', '45', '34', '343', '34', 6556, 323];
12

2-
let arrayOfStrings = ['1','5','45','34','343','34',6556,323];
3-
4-
let newArray = arrayOfStrings.map(function(val){
5-
return (val);
3+
let newArray = mixedDataTypes.map(function(item) {
4+
// Your code here
5+
return item
66
});
77

8-
8+
console.log(newArray);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
let mixedDataTypes = ['1', '5', '45', '34', '343', '34', 6556, 323];
2+
3+
let newArray = mixedDataTypes.map(function(item) {
4+
// Your code here
5+
return typeof(item);
6+
});
7+
8+
console.log(newArray)

exercises/20.4-Map-data-types/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test("You shouldn't delete the variable newArray", function(){
2020
expect(myVar).toBeTruthy();
2121
});
2222

23-
test('The output in the console should match the one in the instructions!', function () {
23+
test('The output in the console should match the one in the instructions', function () {
2424
const _app = rewire('./app.js');
2525

2626
let _arrayOfStrings = ['1','5','45','34','343','34',6556,323];
Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# `20.5` "Mapeando" un arreglo de objetos
1+
# `20.5` Map array of objects
22

33
El escenario más común para la función de mapeo es para simplificar los arreglos dados, por ejemplo:
44

55
El algoritmo actual crea un arreglo con solo los nombres de las personas y los imprime en la consola.
66

77
## 📝 Instrucciones:
88

9-
1. Actualiza la función `map` para que cree un arreglo donde cada elemento contenga lo siguiente:
9+
1. Actualiza la función `simplifier` para que cree un arreglo donde cada elemento contenga lo siguiente:
1010

11-
```js
12-
Hello, my name is Joe and I am 13 years old
11+
```text
12+
Hello, my name is Joe and I am 36 years old
1313
```
1414

15-
## Resultado esperado:
15+
## 💻 Resultado esperado:
1616

17-
Debe quedar algo similar a esto, sin embargo las edades pueden variar.
17+
Debe quedar algo similar a esto, sin embargo, las edades pueden variar.
1818

1919
```js
2020
[ 'Hello, my name is Joe and I am 36 years old',
@@ -24,22 +24,12 @@ Debe quedar algo similar a esto, sin embargo las edades pueden variar.
2424
'Hello, my name is Steve and I am 19 years old' ]
2525
```
2626

27-
## 💡 Pista:
27+
## 💡 Pistas:
2828

2929
+ Debes determinar la edad de cada persona según su fecha de nacimiento (`birthDate`).
3030

31-
+ Busca en Google "Cómo obtener la edad de la fecha de nacimiento dada en JavaScript".
32-
33-
+ Recuerda la edad también depende del mes, si el mes de la fecha actual es mayor o igual al actual suma un año".
31+
+ Busca en Google "Cómo obtener la edad con una fecha de nacimiento dada en JavaScript".
3432

35-
+ Dentro de tu función simplifier, debe devolver una concatenación.
33+
+ Recuerda la edad también depende del día, si el día de la fecha actual es mayor o igual al actual se suma un año.
3634

37-
## Resultado esperado:
38-
39-
```js
40-
[ 'Hello, my name is Joe and I am 13 years old',
41-
'Hello, my name is Bob and I am 42 years old',
42-
'Hello, my name is Erika and I am 28 years old',
43-
'Hello, my name is Dylan and I am 18 years old',
44-
'Hello, my name is Steve and I am 14 years old' ]
45-
```
35+
+ Dentro de tu función `simplifier`, debes devolver una concatenación.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# `20.5` Map array of objects
22

3-
The most common scenario for the mapping function is for simplifying given arrays, for example:
3+
The most common scenario for the mapping function is simplifying given arrays, for example:
44

55
The current algorithm creates an array with only the names of the people and prints it on the console.
66

77
## 📝 Instructions:
88

9-
1. Please update the mapping function so it creates an array where each item contains the following:
9+
1. Please update the `simplifier` function so it creates an array where each item contains the following:
1010

11-
```js
11+
```text
1212
Hello, my name is Joe and I am 36 years old
1313
```
1414

15-
## Expected result:
15+
## 💻 Expected result:
1616

1717
The result should be similar to this, but the ages might be different.
1818

@@ -24,12 +24,12 @@ The result should be similar to this, but the ages might be different.
2424
'Hello, my name is Steve and I am 19 years old' ]
2525
```
2626

27-
## 💡 Hint:
27+
## 💡 Hints:
2828

29-
+ You have to get the age of each people based on their birthDate.
29+
+ You have to get the age of each person based on their `birthDate`.
3030

31-
+ Search in Google "How to get the age of given birth date in javascript".
31+
+ Search in Google "How to get the age of a given birth date in JavaScript".
3232

33-
+ Remember that the age also depends on the month, if the month of the current date is greater than or equal to the current month it adds up to one year".
33+
+ Remember that the age also depends on the day, if the day of the current date is greater than or equal to the current day, it adds up one more year.
3434

35-
+ Inside your simplifier function you have to return a concatenation.
35+
+ Inside your `simplifier` function you have to return a concatenation.

exercises/20.5-Map-arrays-of-objects/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ let people = [
66
{ name: 'Steve', birthDate: new Date(2003,4,24) }
77
];
88

9-
let simplifier = function(person){
9+
let simplifier = function(person) {
10+
// Your code here
1011
return person.name;
1112
};
1213

13-
console.log(people.map(simplifier));
14+
console.log(people.map(simplifier));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
let people = [
2+
{ name: 'Joe', birthDate: new Date(1986,10,24) },
3+
{ name: 'Bob', birthDate: new Date(1975,5,24) },
4+
{ name: 'Erika', birthDate: new Date(1989,6,12) },
5+
{ name: 'Dylan', birthDate: new Date(1999,12,14) },
6+
{ name: 'Steve', birthDate: new Date(2003,4,24) }
7+
];
8+
9+
let simplifier = function(person) {
10+
// Your code here
11+
let currentDate = new Date();
12+
let age = currentDate.getFullYear() - person.birthDate.getFullYear();
13+
let birthDateThisYear = new Date(currentDate.getFullYear(), person.birthDate.getMonth(), person.birthDate.getDate());
14+
15+
if (currentDate < birthDateThisYear) {
16+
age = age - 1;
17+
}
18+
19+
return "Hello, my name is " + person.name + " and I am " + age + " years old";
20+
};
21+
22+
console.log(people.map(simplifier));

exercises/20.5-Map-arrays-of-objects/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test("You shouldn't delete the function named simplifier", function(){
2020
});
2121

2222

23-
test('The output in the console should should look similar but not exactly (years may vary) to the one in the instructions!', function () {
23+
test('The output in the console should look similar but not exactly (years may vary) to the one in the instructions', function () {
2424
const _app = rewire('./app.js');
2525
let _output = []
2626
let _people = [
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# `20.6` Sí y no
1+
# `20.6` Yes and No
22

33
## 📝 Instrucciones:
44

5-
1. Por favor utiliza la funcionalidad del map para recorrer el arreglo de booleanos y crea un nuevo arreglo que contenga el string `wiki` por cada 1 y `woko` por cada 0 que tiene el arreglo original.
5+
1. Utiliza el método `map()` para recorrer el arreglo de booleanos y crea un nuevo arreglo que contenga el string `'wiki'` por cada 1 y `'woko'` por cada 0 que tiene el arreglo dado.
66

7-
2. Imprime ese arreglo en la consola.
7+
2. Imprime el arreglo en la consola.
88

9-
## 💡 Pista:
9+
## 💡 Pistas:
1010

11-
+ Necesitas mapear todo el arreglo
11+
+ Necesitas mapear todo el arreglo.
1212

1313
+ Dentro de tu función de mapeo, necesitas usar un condicional para verificar si el valor actual es `0` o `1`.
1414

15-
+ Si el valor actual es `1`, imprime el string `wiki`.
15+
+ Si el valor actual es `1`, imprime el string `'wiki'`.
1616

17-
+ Si el valor actual es `0`, imprime el string `woko`
17+
+ Si el valor actual es `0`, imprime el string `'woko'`
1818

19-
### Resultado esperado:
19+
## 💻 Resultado esperado:
2020

2121
```js
22-
[ 'woko', 'wiki', 'woko', 'woko', 'wiki', 'wiki', 'wiki', 'woko', 'woko', 'wiki', 'woko', 'wiki', 'wiki', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'wiki', 'woko', 'woko', 'woko', 'woko', 'wiki' ]
23-
```
22+
[ 'woko', 'wiki', 'woko', 'woko', 'wiki', 'wiki', 'wiki', 'woko', 'woko', 'wiki', 'woko', 'wiki', 'wiki', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'wiki', 'woko', 'woko', 'woko', 'woko', 'wiki' ]
23+
```

exercises/20.6-Yes-and-no/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
## 📝 Instructions:
44

5-
1. Please use the Array map functionality to loop the array of booleans and create a new array that contains the string `wiki` for every 1 and `woko` for every 0 that the original array had.
5+
1. Use the `map()` method to loop the array of booleans and create a new array that contains the string `'wiki'` for every 1 and `'woko'` for every 0 that the given array has.
66

7-
2. Print that array on the console.
7+
2. Print the array on the console.
88

9-
## 💡 Hint:
9+
## 💡 Hints:
1010

11-
+ You need to map the entire array
11+
+ You need to map the entire array.
1212

1313
+ Inside your mapping function you need to use a conditional to verify if the current value is `0` or `1`.
1414

15-
+ If the current value is `1` you print the string `wiki`.
15+
+ If the current value is `1` you print the string `'wiki'`.
1616

17-
+ If the current value is `0` you print the string `woko`.
17+
+ If the current value is `0` you print the string `'woko'`.
1818

19-
### Expected result:
19+
## 💻 Expected result:
2020

2121
```js
22-
[ 'woko', 'wiki', 'woko', 'woko', 'wiki', 'wiki', 'wiki', 'woko', 'woko', 'wiki', 'woko', 'wiki', 'wiki', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'wiki', 'woko', 'woko', 'woko', 'woko', 'wiki' ]
23-
```
22+
[ 'woko', 'wiki', 'woko', 'woko', 'wiki', 'wiki', 'wiki', 'woko', 'woko', 'wiki', 'woko', 'wiki', 'wiki', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'wiki', 'woko', 'woko', 'woko', 'woko', 'wiki' ]
23+
```

exercises/20.6-Yes-and-no/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
let theBools = [0,1,0,0,1,1,1,0,0,1,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1];
1+
let theBools = [0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
22

3-
//your code here
3+
// Your code here
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let theBools = [0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
2+
3+
// Your code here
4+
5+
let newArray = theBools.map(function(item) {
6+
if (item === 0) return "woko"
7+
else if(item === 1) return "wiki"
8+
})
9+
10+
console.log(newArray)

exercises/20.6-Yes-and-no/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test('You have to use the console.log function to print the correct output', fun
1414
expect(console.log.mock.calls.length > 0).toBe(true);
1515
});
1616

17-
test('The output in the console should match the one in the instructions!', function () {
17+
test('The output in the console should match the one in the instructions', function () {
1818
const _app = rewire('./app.js');
1919
let _output = []
2020
let _theBools = [0,1,0,0,1,1,1,0,0,1,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1];

exercises/21-Filter-an-array/README.es.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# `21` Filter an Array
22

3-
Otra función sorprendente para los arreglos o arrays es `array.filter()` (filtrar). Recorre todo el arreglo original y solo devuelve los valores que coinciden con una condición particular.
3+
Otra función sorprendente para los arrays es `array.filter()`. Recorre todo el arreglo original y solo devuelve los valores que coinciden con una condición particular.
44

5-
[Aquí está la documentación de la función `filter` en w3school](https://www.w3schools.com/jsref/jsref_filter.asp)
5+
[Aquí está la documentación](https://www.w3schools.com/jsref/jsref_filter.asp) de la función `filter()` en w3schools.
66

77
Por ejemplo, este algoritmo filtra el arreglo `allNumbers` y devuelve un nuevo arreglo con solo los números impares:
88

99
```js
1010
let allNumbers = [23,12,35,5,3,2,3,54,3,21,534,23,42,1];
1111

12-
let onlyOdds = allNumbers.filter(function(number){
12+
let onlyOdds = allNumbers.filter(function(number) {
1313
return (number % 2 > 0)
1414
});
1515

@@ -24,4 +24,4 @@ console.log(onlyOdds);
2424

2525
## 💡 Pista:
2626

27-
+ Aquí hay un video de 2:29 min explicando la [función `array.filter()`](https://www.youtube.com/watch?v=0qsFDFC2oEE9)
27+
+ [Aquí hay un video de 2 min](https://www.youtube.com/watch?v=0qsFDFC2oEE) explicando la función `array.filter()`.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# `21` Filter an Array
22

3-
Another amazing function for arrays is `array.filter()`.
4-
It loops the entire original array and only returns the values that match a particular condition.
3+
Another amazing function for arrays is `array.filter()`. It loops the entire original array and only returns the values that match a particular condition.
54

6-
[Here is the documentation of the `filter` function in w3school](https://www.w3schools.com/jsref/jsref_filter.asp)
5+
[Here is the documentation](https://www.w3schools.com/jsref/jsref_filter.asp) of the `filter()` function in w3schools.
76

87
For example, this algorithm filters the `allNumbers` array and returns a new array with only the odds numbers:
98

109
```js
1110
let allNumbers = [23,12,35,5,3,2,3,54,3,21,534,23,42,1];
1211

13-
let onlyOdds = allNumbers.filter(function(number){
12+
let onlyOdds = allNumbers.filter(function(number) {
1413
return (number % 2 > 0)
1514
});
1615

@@ -21,8 +20,8 @@ console.log(onlyOdds);
2120

2221
1. Complete the code to make it fill the `resultingNames` array with only the names that start with letter R.
2322

24-
2. Use the `array.filter` function
23+
2. Use the `array.filter()` function.
2524

2625
## 💡 Hint:
2726

28-
+ Here is a 2:29 min video explaining [array.filter function](https://www.youtube.com/watch?v=0qsFDFC2oEE)
27+
+ [Here is a 2:29 min video](https://www.youtube.com/watch?v=0qsFDFC2oEE) explaining `array.filter()` function.

exercises/21-Filter-an-array/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
let allNames = ["Romario","Boby","Roosevelt","Emiliy", "Michael", "Greta", "Patricia", "Danzalee"];
1+
let allNames = ["Romario", "Boby", "Roosevelt", "Emiliy", "Michael", "Greta", "Patricia", "Danzalee"];
22

3-
//your code here
3+
// Your code here
44

5-
console.log(resultingNames);
5+
console.log(resultingNames);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let allNames = ["Romario", "Boby", "Roosevelt", "Emiliy", "Michael", "Greta", "Patricia", "Danzalee"];
2+
3+
// Your code here
4+
5+
let resultingNames = allNames.filter(function(item) {
6+
return item[0] === "R";
7+
});
8+
9+
console.log(resultingNames);

0 commit comments

Comments
 (0)