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-
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 = [

0 commit comments

Comments
 (0)