You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 09-Data-Structure-Modern-Operators-and-Strings/challenge.js
+46
Original file line number
Diff line number
Diff line change
@@ -219,3 +219,49 @@ console.log(scorers);
219
219
// ----------------------------------------
220
220
// Coding Challenge #3
221
221
// ----------------------------------------
222
+
223
+
/*
224
+
Let's continue with our football betting app! This time, we have a map with a log of the events that happened during the game, The values are the events themselves, and the keys are the minutes in which each event happened (a football game has 90 minutes plus some extra time).
225
+
226
+
1. Create an array 'events' of the different game events that happened (no duplicates).
227
+
2. After the game has finished, it was found that the yellow card from minute 64 was unfair. So remove this event from the game events log.
228
+
3. Print the following string to the console: "An event happened, on average every 9 minutes" (keep in mind that a game has 90 minutes).
229
+
4. Loop over the events and log them to the console, marking wether it's in the first half or second half. (after 45min) of the game, like this: [FIRST HALF] 17: ⚽ GOAL
230
+
*/
231
+
232
+
constgameEvents=newMap([
233
+
[17,"⚽️ GOAL"],
234
+
[36,"🔁 Substitution"],
235
+
[47,"⚽️ GOAL"],
236
+
[61,"🔁 Substitution"],
237
+
[64,"🟨 Yellow card"],
238
+
[69,"🟥 Red card"],
239
+
[70,"🔁 Substitution"],
240
+
[72,"🔁 Substitution"],
241
+
[76,"⚽️ GOAL"],
242
+
[80,"⚽️ GOAL"],
243
+
[92,"🟨 Yellow card"],
244
+
]);
245
+
246
+
// 1.
247
+
constx=newSet(gameEvents.values());
248
+
constevents=[...x];
249
+
console.log(events);
250
+
251
+
// 2.
252
+
gameEvents.delete(64);
253
+
console.log(gameEvents);
254
+
255
+
// 3.
256
+
console.log(
257
+
`An event happened, on average every ${90/gameEvents.size} minutes`
0 commit comments