-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from josemoracard/jose6-20.4-Map-data-types
- Loading branch information
Showing
50 changed files
with
369 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
] | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.