-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathexercise-2.js
More file actions
94 lines (88 loc) · 1.67 KB
/
exercise-2.js
File metadata and controls
94 lines (88 loc) · 1.67 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
90
91
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",
},
];
//task 1
hogwarts.filter(obj => {
let {house} = obj;
return house === "Gryffindor";
}).forEach(obj => {
let {firstName, lastName} = obj;
console.log(`${firstName} ${lastName}`);
})
// task 2
hogwarts.filter(teacher => {
let {occupation} = teacher;
return occupation === "Teacher" && teacher.pet !== null;
}).forEach(teacher => {
let {firstName, lastName} = teacher;
console.log(`${firstName} ${lastName}`);
})