Skip to content

Commit

Permalink
Merge pull request #139 from josemoracard/jose6-20.4-Map-data-types
Browse files Browse the repository at this point in the history
  • Loading branch information
alesanchezr authored Sep 14, 2023
2 parents bab53d3 + 6ff7381 commit b442390
Show file tree
Hide file tree
Showing 50 changed files with 369 additions and 228 deletions.
17 changes: 10 additions & 7 deletions exercises/20.4-Map-data-types/README.es.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# `20.4` `Map` y tipos de datos

Algunas veces los arreglos vienen con valores mixtos y debes unificarlos en un solo tipo de datos.
# `20.4` Map data types

## 📝 Instrucciones:

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.
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.

## 💡 Pista:

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

## Resultado esperado:
## 💻 Resultado esperado:

```js
[string,string,... ,number,string,...]
[
'string', 'string',
'string', 'string',
'string', 'string',
'number', 'number'
]
```
15 changes: 9 additions & 6 deletions exercises/20.4-Map-data-types/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# `20.4` Map data types

Some times arrays come with mixed values and you need to unify them into only one data type.

## 📝 Instructions:

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.
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.

## 💡 Hint:

+ Use the `typeof` function to get the data type.
## Expected result:

## 💻 Expected result:

```js
[string,string,... ,number,string,...]
[
'string', 'string',
'string', 'string',
'string', 'string',
'number', 'number'
]
```

10 changes: 5 additions & 5 deletions exercises/20.4-Map-data-types/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
let mixedDataTypes = ['1', '5', '45', '34', '343', '34', 6556, 323];

let arrayOfStrings = ['1','5','45','34','343','34',6556,323];

let newArray = arrayOfStrings.map(function(val){
return (val);
let newArray = mixedDataTypes.map(function(item) {
// Your code here
return item
});


console.log(newArray);
8 changes: 8 additions & 0 deletions exercises/20.4-Map-data-types/solution.hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let mixedDataTypes = ['1', '5', '45', '34', '343', '34', 6556, 323];

let newArray = mixedDataTypes.map(function(item) {
// Your code here
return typeof(item);
});

console.log(newArray)
2 changes: 1 addition & 1 deletion exercises/20.4-Map-data-types/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test("You shouldn't delete the variable newArray", function(){
expect(myVar).toBeTruthy();
});

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

let _arrayOfStrings = ['1','5','45','34','343','34',6556,323];
Expand Down
30 changes: 10 additions & 20 deletions exercises/20.5-Map-arrays-of-objects/README.es.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# `20.5` "Mapeando" un arreglo de objetos
# `20.5` Map array of objects

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

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

## 📝 Instrucciones:

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

```js
Hello, my name is Joe and I am 13 years old
```text
Hello, my name is Joe and I am 36 years old
```

## Resultado esperado:
## 💻 Resultado esperado:

Debe quedar algo similar a esto, sin embargo las edades pueden variar.
Debe quedar algo similar a esto, sin embargo, las edades pueden variar.

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

## 💡 Pista:
## 💡 Pistas:

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

+ Busca en Google "Cómo obtener la edad de la fecha de nacimiento dada en JavaScript".

+ 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".
+ Busca en Google "Cómo obtener la edad con una fecha de nacimiento dada en JavaScript".

+ Dentro de tu función simplifier, debe devolver una concatenación.
+ 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.

## Resultado esperado:

```js
[ 'Hello, my name is Joe and I am 13 years old',
'Hello, my name is Bob and I am 42 years old',
'Hello, my name is Erika and I am 28 years old',
'Hello, my name is Dylan and I am 18 years old',
'Hello, my name is Steve and I am 14 years old' ]
```
+ Dentro de tu función `simplifier`, debes devolver una concatenación.
18 changes: 9 additions & 9 deletions exercises/20.5-Map-arrays-of-objects/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# `20.5` Map array of objects

The most common scenario for the mapping function is for simplifying given arrays, for example:
The most common scenario for the mapping function is simplifying given arrays, for example:

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

## 📝 Instructions:

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

```js
```text
Hello, my name is Joe and I am 36 years old
```

## Expected result:
## 💻 Expected result:

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

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

## 💡 Hint:
## 💡 Hints:

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

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

+ 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".
+ 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.

+ Inside your simplifier function you have to return a concatenation.
+ Inside your `simplifier` function you have to return a concatenation.
5 changes: 3 additions & 2 deletions exercises/20.5-Map-arrays-of-objects/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ let people = [
{ name: 'Steve', birthDate: new Date(2003,4,24) }
];

let simplifier = function(person){
let simplifier = function(person) {
// Your code here
return person.name;
};

console.log(people.map(simplifier));
console.log(people.map(simplifier));
22 changes: 22 additions & 0 deletions exercises/20.5-Map-arrays-of-objects/solution.hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let people = [
{ name: 'Joe', birthDate: new Date(1986,10,24) },
{ name: 'Bob', birthDate: new Date(1975,5,24) },
{ name: 'Erika', birthDate: new Date(1989,6,12) },
{ name: 'Dylan', birthDate: new Date(1999,12,14) },
{ name: 'Steve', birthDate: new Date(2003,4,24) }
];

let simplifier = function(person) {
// Your code here
let currentDate = new Date();
let age = currentDate.getFullYear() - person.birthDate.getFullYear();
let birthDateThisYear = new Date(currentDate.getFullYear(), person.birthDate.getMonth(), person.birthDate.getDate());

if (currentDate < birthDateThisYear) {
age = age - 1;
}

return "Hello, my name is " + person.name + " and I am " + age + " years old";
};

console.log(people.map(simplifier));
2 changes: 1 addition & 1 deletion exercises/20.5-Map-arrays-of-objects/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test("You shouldn't delete the function named simplifier", function(){
});


test('The output in the console should should look similar but not exactly (years may vary) to the one in the instructions!', function () {
test('The output in the console should look similar but not exactly (years may vary) to the one in the instructions', function () {
const _app = rewire('./app.js');
let _output = []
let _people = [
Expand Down
20 changes: 10 additions & 10 deletions exercises/20.6-Yes-and-no/README.es.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# `20.6` Sí y no
# `20.6` Yes and No

## 📝 Instrucciones:

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.
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.

2. Imprime ese arreglo en la consola.
2. Imprime el arreglo en la consola.

## 💡 Pista:
## 💡 Pistas:

+ Necesitas mapear todo el arreglo
+ Necesitas mapear todo el arreglo.

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

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

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

### Resultado esperado:
## 💻 Resultado esperado:

```js
[ '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' ]
```
[ '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' ]
```
18 changes: 9 additions & 9 deletions exercises/20.6-Yes-and-no/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

## 📝 Instructions:

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.
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.

2. Print that array on the console.
2. Print the array on the console.

## 💡 Hint:
## 💡 Hints:

+ You need to map the entire array
+ You need to map the entire array.

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

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

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

### Expected result:
## 💻 Expected result:

```js
[ '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' ]
```
[ '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' ]
```
4 changes: 2 additions & 2 deletions exercises/20.6-Yes-and-no/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
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];
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];

//your code here
// Your code here
10 changes: 10 additions & 0 deletions exercises/20.6-Yes-and-no/solution.hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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];

// Your code here

let newArray = theBools.map(function(item) {
if (item === 0) return "woko"
else if(item === 1) return "wiki"
})

console.log(newArray)
2 changes: 1 addition & 1 deletion exercises/20.6-Yes-and-no/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('You have to use the console.log function to print the correct output', fun
expect(console.log.mock.calls.length > 0).toBe(true);
});

test('The output in the console should match the one in the instructions!', function () {
test('The output in the console should match the one in the instructions', function () {
const _app = rewire('./app.js');
let _output = []
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];
Expand Down
8 changes: 4 additions & 4 deletions exercises/21-Filter-an-array/README.es.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# `21` Filter an Array

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.
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.

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

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

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

let onlyOdds = allNumbers.filter(function(number){
let onlyOdds = allNumbers.filter(function(number) {
return (number % 2 > 0)
});

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

## 💡 Pista:

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

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

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

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

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

let onlyOdds = allNumbers.filter(function(number){
let onlyOdds = allNumbers.filter(function(number) {
return (number % 2 > 0)
});

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

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

2. Use the `array.filter` function
2. Use the `array.filter()` function.

## 💡 Hint:

+ Here is a 2:29 min video explaining [array.filter function](https://www.youtube.com/watch?v=0qsFDFC2oEE)
+ [Here is a 2:29 min video](https://www.youtube.com/watch?v=0qsFDFC2oEE) explaining `array.filter()` function.
6 changes: 3 additions & 3 deletions exercises/21-Filter-an-array/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let allNames = ["Romario","Boby","Roosevelt","Emiliy", "Michael", "Greta", "Patricia", "Danzalee"];
let allNames = ["Romario", "Boby", "Roosevelt", "Emiliy", "Michael", "Greta", "Patricia", "Danzalee"];

//your code here
// Your code here

console.log(resultingNames);
console.log(resultingNames);
9 changes: 9 additions & 0 deletions exercises/21-Filter-an-array/solution.hide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let allNames = ["Romario", "Boby", "Roosevelt", "Emiliy", "Michael", "Greta", "Patricia", "Danzalee"];

// Your code here

let resultingNames = allNames.filter(function(item) {
return item[0] === "R";
});

console.log(resultingNames);
Loading

0 comments on commit b442390

Please sign in to comment.