This repository was archived by the owner on Apr 18, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathexercise.js
More file actions
91 lines (85 loc) · 1.9 KB
/
exercise.js
File metadata and controls
91 lines (85 loc) · 1.9 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
let hogwarts = [
{
firstName: "Harry",
lastName: "Potter",
house: "Gryffindor",
pet: "Owl",
occupation: "Student",
},
{
firstName: "Ron",
lastName: "Weasley",
house: "Gryffindor",
pet: "Scabbers",
occupation: "Student",
},
{
firstName: "Hermione",
lastName: "Granger",
house: "Gryffindor",
pet: "Cat",
occupation: "Student",
},
{
firstName: "Draco",
lastName: "Malfoy",
house: "Slytherin",
pet: null,
occupation: "Student",
},
{
firstName: "Cedric",
lastName: "Diggory",
house: "HufflePuff",
pet: null,
occupation: "Student",
},
{
firstName: "Severus",
lastName: "Snape",
house: "Slytherin",
pet: null,
occupation: "Teacher",
},
{
firstName: "Filius",
lastName: "Flitwick",
house: "Ravenclaw",
pet: null,
occupation: "Teacher",
},
{
firstName: "Pomona",
lastName: "Sprout",
house: "Hufflepuff",
pet: null,
occupation: "Teacher",
},
{
firstName: "Minerva",
lastName: "McGonagall",
house: "Gryffindor",
pet: null,
occupation: "Teacher",
},
{
firstName: "Albus",
lastName: "Dumbledore",
house: "Gryffindor",
pet: "Phoenix",
occupation: "Teacher",
},
];
let { firstName, lastName, house, pet} = hogwarts;
function property(array){
let gryfindorHouse = array.filter(hogwarts => hogwarts.house === "Gryffindor") //filter mean to give only the elements that pass a certain condition specified by a provided function
let getAllName = gryfindorHouse.map( hogwarts =>`${hogwarts.firstName}${hogwarts.lastName}`);
return getAllName;
}
console.log(property(hogwarts));
function whoHavePet(array){
let findPet = array.filter(hogwarts => hogwarts.pet !== null)
let getPet = findPet.map( hogwarts =>`${hogwarts.firstName}${hogwarts.lastName}`);
return getPet;
}
console.log(whoHavePet(hogwarts));