-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore_objectMaster.js
More file actions
73 lines (61 loc) · 3.45 KB
/
Core_objectMaster.js
File metadata and controls
73 lines (61 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const pokemon = Object.freeze([
{ "id": 1, "name": "Bulbasaur", "types": ["poison", "grass"] },
{ "id": 5, "name": "Charmeleon", "types": ["fire"] },
{ "id": 9, "name": "Blastoise", "types": ["water"] },
{ "id": 12, "name": "Butterfree", "types": ["bug", "flying"] },
{ "id": 16, "name": "Pidgey", "types": ["normal", "flying"] },
{ "id": 23, "name": "Ekans", "types": ["poison"] },
{ "id": 24, "name": "Arbok", "types": ["poison"] },
{ "id": 25, "name": "Pikachu", "types": ["electric"] },
{ "id": 35, "name": "Clefairy", "types": ["normal"] },
{ "id": 37, "name": "Vulpix", "types": ["fire"] },
{ "id": 52, "name": "Meowth", "types": ["normal"] },
{ "id": 63, "name": "Abra", "types": ["psychic"] },
{ "id": 67, "name": "Machamp", "types": ["fighting"] },
{ "id": 72, "name": "Tentacool", "types": ["water", "poison"] },
{ "id": 74, "name": "Geodude", "types": ["rock", "ground"] },
{ "id": 87, "name": "Dewgong", "types": ["water", "ice"] },
{ "id": 98, "name": "Krabby", "types": ["water"] },
{ "id": 115, "name": "Kangaskhan", "types": ["normal"] },
{ "id": 122, "name": "Mr. Mime", "types": ["psychic"] },
{ "id": 133, "name": "Eevee", "types": ["normal"] },
{ "id": 144, "name": "Articuno", "types": ["ice", "flying"] },
{ "id": 145, "name": "Zapdos", "types": ["electric", "flying"] },
{ "id": 146, "name": "Moltres", "types": ["fire", "flying"] },
{ "id": 148, "name": "Dragonair", "types": ["dragon"] }
]);
// an array of pokémon objects where the id is evenly divisible by 3
const pokemonDivisibleByThree = pokemon.filter( p => p.id% 3 === 0)
console.log(pokemonDivisibleByThree);
// an array of pokémon objects that are "fire" type
const pokemonTypeOfFire = pokemon.filter( p => p.types.includes("fire"))
console.log(pokemonTypeOfFire);
// an array of pokémon objects that have more than one type
const pokemonTypesMoreThanOne = pokemon.filter( p => p.types.length >1)
console.log(pokemonTypesMoreThanOne);
// an array with just the names of the pokémon
const pokemonNames = pokemon.map ( p => p.name)
console.log(pokemonNames);
// an array with just the names of pokémon with an id greater than 99
const pokemonNamesWithIdMoreThan99 = pokemon.filter ( p => p.id > 99).map(p => p.name)
console.log(pokemonNamesWithIdMoreThan99);
// an array with just the names of the pokémon whose only type is poison
const pokemonNamesWithTypeOfPoison = pokemon.filter(p => p.types == "poison").map(p => p.name)
console.log(pokemonNamesWithTypeOfPoison);
// an array containing just the first type of all the pokémon whose second type is "flying"
const pokemonSecondOfTypeOfFlying = pokemon.filter(p => p.types[1] == "flying").map(p => p.types[0])
console.log(pokemonSecondOfTypeOfFlying);
// a count of the number of pokémon that are "normal" type
const pokemonCountofTypesOfNormal = pokemon.filter(p => p.types.includes("normal")).length
console.log(pokemonCountofTypesOfNormal);
// an array with all pokemon except the pokemon with the id of 148
const pokemonWithoutIdOf148 = pokemon.filter(p => p.id != 148)
console.log(pokemonWithoutIdOf148);
// an array with all pokemon and for pokemon id: 35 replacing "normal" with "fairy"
const pokemonByIdOf35 = pokemon.map(p => {
if (p.id === 35){
return {...p, types: p.types.map(type => type === "normal" ? "fairy": type)}
}
return p
})
console.log(pokemonByIdOf35);