-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoal1.js
More file actions
244 lines (241 loc) · 6.41 KB
/
soal1.js
File metadata and controls
244 lines (241 loc) · 6.41 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
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
const users = [
{
"_id": "64ef3bb5f508b89b6896fdf4",
"name": "Yoga",
"eyeColor": "blue",
"age": 22,
"balance": "$1,609.63",
"gender": "female",
"company": "QUAILCOM",
"email": "jeaninebauer@quailcom.com",
"phone": "+1 (911) 539-2871",
"address": "700 Seaview Avenue, Trona, Wyoming, 9794",
"registered": "2014-09-26T02:11:06 -07:00",
"friends": [
{
"id": 0,
"name": "Imam"
},
{
"id": 1,
"name": "Adella"
},
{
"id": 2,
"name": "Alim"
}
],
"favoriteFruit": "strawberry"
},
{
"_id": "64ef3bb5eff923ac29b9548e",
"name": "Dorsey Jimenez",
"eyeColor": "brown",
"age": 34,
"balance": "$3,149.90",
"gender": "male",
"company": "TROPOLI",
"email": "dorseyjimenez@tropoli.com",
"phone": "+1 (978) 494-2582",
"address": "414 Elton Street, Fairforest, Northern Mariana Islands, 371",
"registered": "2014-06-30T10:12:26 -07:00",
"friends": [
{
"id": 0,
"name": "Imam"
},
{
"id": 1,
"name": "Irfi"
},
{
"id": 2,
"name": "Irfi"
}
],
"favoriteFruit": "strawberry"
},
{
"_id": "64ef3bb5844c559ed1f25b3d",
"name": "Lavonne Boone",
"eyeColor": "green",
"age": 34,
"balance": "$3,990.54",
"gender": "female",
"company": "VIXO",
"email": "lavonneboone@vixo.com",
"phone": "+1 (966) 415-2906",
"address": "892 Cortelyou Road, Gibsonia, Nevada, 2328",
"registered": "2016-10-22T10:27:48 -07:00",
"friends": [
{
"id": 0,
"name": "Irfi"
},
{
"id": 1,
"name": "Irfi"
},
{
"id": 2,
"name": "Adella"
}
],
"favoriteFruit": "apple"
},
{
"_id": "64ef3bb55de3c0e00a0e838f",
"name": "Lorna Serrano",
"eyeColor": "blue",
"age": 22,
"balance": "$3,065.11",
"gender": "female",
"company": "LINGOAGE",
"email": "lornaserrano@lingoage.com",
"phone": "+1 (904) 575-3489",
"address": "144 Schroeders Avenue, Stollings, Kentucky, 9059",
"registered": "2016-09-18T06:39:15 -07:00",
"friends": [
{
"id": 0,
"name": "Adrian"
},
{
"id": 1,
"name": "Alim"
},
{
"id": 2,
"name": "Grace"
}
],
"favoriteFruit": "banana"
},
{
"_id": "64ef3bb5cdf2fd810edfb07d",
"name": "Romero Franco",
"eyeColor": "green",
"age": 33,
"balance": "$3,193.23",
"gender": "male",
"company": "PLASMOSIS",
"email": "romerofranco@plasmosis.com",
"phone": "+1 (857) 598-2026",
"address": "577 Bush Street, Martinez, Vermont, 8937",
"registered": "2014-03-20T02:55:38 -07:00",
"friends": [
{
"id": 0,
"name": "Adella"
},
{
"id": 1,
"name": "Imam"
},
{
"id": 2,
"name": "Imam"
}
],
"favoriteFruit": "banana"
},
{
"_id": "64ef3bb582c832cb387f3e3f",
"name": "Polly Colon",
"eyeColor": "brown",
"age": 37,
"balance": "$2,795.85",
"gender": "female",
"company": "ACCUSAGE",
"email": "pollycolon@accusage.com",
"phone": "+1 (807) 503-3272",
"address": "968 Roosevelt Court, Fairmount, North Dakota, 2836",
"registered": "2023-04-30T09:36:59 -07:00",
"friends": [
{
"id": 0,
"name": "Adella"
},
{
"id": 1,
"name": "Adrian"
},
{
"id": 2,
"name": "Imam"
}
],
"favoriteFruit": "apple"
},
{
"_id": "64ef3bb55dd2e5b1c7b22033",
"name": "Salazar Juarez",
"eyeColor": "green",
"age": 21,
"balance": "$3,353.87",
"gender": "male",
"company": "RODEMCO",
"email": "salazarjuarez@rodemco.com",
"phone": "+1 (905) 484-2854",
"address": "412 Kosciusko Street, Williamson, Arkansas, 9026",
"registered": "2015-03-25T05:08:08 -07:00",
"friends": [
{
"id": 0,
"name": "Grace"
},
{
"id": 1,
"name": "Imam"
},
{
"id": 2,
"name": "Imam"
}
],
"favoriteFruit": "apple"
},
{
"_id": "64ef3bb5117ec9f7109dbf5a",
"name": "Compton Carlson",
"eyeColor": "brown",
"age": 34,
"balance": "$3,445.30",
"gender": "male",
"company": "ZAJ",
"email": "comptoncarlson@zaj.com",
"phone": "+1 (975) 424-2237",
"address": "873 Turnbull Avenue, Tedrow, Texas, 6811",
"registered": "2017-02-23T06:27:01 -07:00",
"friends": [
{
"id": 0,
"name": "Imam"
},
{
"id": 1,
"name": "Adella"
},
{
"id": 2,
"name": "Imam"
}
],
"favoriteFruit": "banana"
}
]
// 1) tentukan yang mempunyai buah favorit dia nya banana
const checkFavFruit = (data) => {
// 1. bikin variable array kosong
let result = [];
// 2. looping untuk mengecheck satu satu data
for (let i = 0; i < data.length; i++) {
// 3. check data favorit fruit yang nilai nya banana
if (data[i].favoriteFruit === 'banana') {
// 4. masukkan data yang sesuai hasil check kondisi di atas
result.push(data[i])
}
}
return result;
}
console.log(checkFavFruit(users));