-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoal5.js
276 lines (272 loc) · 7.17 KB
/
soal5.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// tentukan user yang eyeColor nya blue dan ada berapa jumlah nya
// 1. buat function getEyeColor
function getEyeColor(data){
// 2. buat variable result berupa array kosong yg nantinya utk menyimpan data yang sudah difilter
let result = []
// 3. looping cek semua data 1 1
for(let i = 0; i < data.length; i++){
// 4. buat filter untuk user eyeColor blue
if(data[i].eyeColor === "blue"){
// 5. push datanya ke variable result
result.push(data[i])
}
}
// 6. mengembalikan data
return result
}
const users = [
{
"_id": "64f0873bd80eb663848b6dcf",
"name": "Terra Briggs",
"eyeColor": "green",
"age": 35,
"balance": "$3,105.86",
"gender": "female",
"company": "MAXIMIND",
"email": "[email protected]",
"phone": "+1 (932) 480-3039",
"address": "435 Livonia Avenue, Keyport, Federated States Of Micronesia, 6768",
"registered": "2017-06-04T09:23:40 -07:00",
"friends": [
{
"id": 0,
"name": "Irfi"
},
{
"id": 1,
"name": "Alim"
},
{
"id": 2,
"name": "Adella"
}
],
"favoriteFruit": "apple"
},
{
"_id": "64f0873b3639550701a7616d",
"name": "Earline Fulton",
"eyeColor": "blue",
"age": 26,
"balance": "$3,223.89",
"gender": "female",
"company": "GINKLE",
"email": "[email protected]",
"phone": "+1 (977) 576-3497",
"address": "963 Garden Street, Jugtown, Louisiana, 8124",
"registered": "2016-02-24T07:08:23 -07:00",
"friends": [
{
"id": 0,
"name": "Imam"
},
{
"id": 1,
"name": "Adella"
},
{
"id": 2,
"name": "Imam"
}
],
"favoriteFruit": "banana"
},
{
"_id": "64f0873b6f1d88fde7bc7ae9",
"name": "Ava Holland",
"eyeColor": "green",
"age": 37,
"balance": "$3,391.03",
"gender": "female",
"company": "SPEEDBOLT",
"email": "[email protected]",
"phone": "+1 (852) 532-2296",
"address": "164 Amity Street, Utting, Kentucky, 7033",
"registered": "2017-05-12T01:28:23 -07:00",
"friends": [
{
"id": 0,
"name": "Adrian"
},
{
"id": 1,
"name": "Adella"
},
{
"id": 2,
"name": "Grace"
}
],
"favoriteFruit": "apple"
},
{
"_id": "64f0873bc20a6ad9a2146bad",
"name": "Villarreal William",
"eyeColor": "blue",
"age": 39,
"balance": "$2,815.63",
"gender": "male",
"company": "VISUALIX",
"email": "[email protected]",
"phone": "+1 (946) 499-3563",
"address": "764 Cherry Street, Graball, Texas, 9175",
"registered": "2016-09-05T10:40:50 -07:00",
"friends": [
{
"id": 0,
"name": "Grace"
},
{
"id": 1,
"name": "Grace"
},
{
"id": 2,
"name": "Imam"
}
],
"favoriteFruit": "banana"
},
{
"_id": "64f0873b73ce9a4e6c1155fb",
"name": "Monica Contreras",
"eyeColor": "brown",
"age": 30,
"balance": "$1,245.27",
"gender": "female",
"company": "SENMEI",
"email": "[email protected]",
"phone": "+1 (907) 428-2705",
"address": "788 Macdougal Street, Newcastle, Oklahoma, 7823",
"registered": "2020-09-17T01:16:41 -07:00",
"friends": [
{
"id": 0,
"name": "Adrian"
},
{
"id": 1,
"name": "Irfi"
},
{
"id": 2,
"name": "Grace"
}
],
"favoriteFruit": "strawberry"
},
{
"_id": "64f0873b1d9164403e3fe13b",
"name": "Betty Fletcher",
"eyeColor": "green",
"age": 29,
"balance": "$2,759.56",
"gender": "female",
"company": "INTERLOO",
"email": "[email protected]",
"phone": "+1 (910) 493-3522",
"address": "408 Gelston Avenue, Oceola, North Dakota, 5404",
"registered": "2019-10-22T04:57:59 -07:00",
"friends": [
{
"id": 0,
"name": "Alim"
},
{
"id": 1,
"name": "Adella"
},
{
"id": 2,
"name": "Alim"
}
],
"favoriteFruit": "strawberry"
},
{
"_id": "64f0873b2afdad5c25834bf6",
"name": "Grace Perkins",
"eyeColor": "blue",
"age": 40,
"balance": "$3,152.90",
"gender": "female",
"company": "ECSTASIA",
"email": "[email protected]",
"phone": "+1 (997) 530-2373",
"address": "823 Paerdegat Avenue, Croom, Colorado, 3298",
"registered": "2016-12-03T09:11:34 -07:00",
"friends": [
{
"id": 0,
"name": "Grace"
},
{
"id": 1,
"name": "Alim"
},
{
"id": 2,
"name": "Adella"
}
],
"favoriteFruit": "strawberry"
},
{
"_id": "64f0873b6eddaeed32a85b8c",
"name": "Carmella Raymond",
"eyeColor": "brown",
"age": 37,
"balance": "$3,491.93",
"gender": "female",
"company": "ZOINAGE",
"email": "[email protected]",
"phone": "+1 (864) 515-2800",
"address": "383 Irving Street, Whipholt, Vermont, 3809",
"registered": "2015-02-07T02:27:38 -07:00",
"friends": [
{
"id": 0,
"name": "Irfi"
},
{
"id": 1,
"name": "Grace"
},
{
"id": 2,
"name": "Imam"
}
],
"favoriteFruit": "banana"
},
{
"_id": "64f0873b730d5afe1dd567c1",
"name": "Taylor Dean",
"eyeColor": "green",
"age": 35,
"balance": "$3,740.06",
"gender": "male",
"company": "KOG",
"email": "[email protected]",
"phone": "+1 (802) 550-3768",
"address": "524 Dinsmore Place, Austinburg, Utah, 771",
"registered": "2018-07-21T02:48:34 -07:00",
"friends": [
{
"id": 0,
"name": "Adrian"
},
{
"id": 1,
"name": "Grace"
},
{
"id": 2,
"name": "Grace"
}
],
"favoriteFruit": "banana"
}
]
console.log(getEyeColor(users))
console.log(`Jumlah user yang eyeColor blue ada ${getEyeColor(users).length}`)