-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge3.js
More file actions
43 lines (36 loc) · 1.5 KB
/
Copy pathchallenge3.js
File metadata and controls
43 lines (36 loc) · 1.5 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
/*
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).
1. Create an array 'events' of the different game events that happened (no duplicates)
2. After the game has finished, is was found that the yellow card from minute 64 was unfair. So remove this event from the game events log.
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)
4. Loop over the events and log them to the console, marking whether it's in the first half or second half (after 45 min) of the game, like this:
[FIRST HALF] 17: ⚽️ GOAL
GOOD LUCK 😀
*/
const gameEvents = new Map([
[17, '⚽️ GOAL'],
[36, '🔁 Substitution'],
[47, '⚽️ GOAL'],
[61, '🔁 Substitution'],
[64, '🔶 Yellow card'],
[69, '🔴 Red card'],
[70, '🔁 Substitution'],
[72, '🔁 Substitution'],
[76, '⚽️ GOAL'],
[80, '⚽️ GOAL'],
[92, '🔶 Yellow card'],
]);
//1
const events = [...new Set(gameEvents.values())];
console.log(events);
//2
gameEvents.delete(64);
console.log(gameEvents);
//3
console.log(`event happen every ${90 / (gameEvents.size - 1)}`);
//4
for (const [key, value] of gameEvents) {
key < 45
? console.log(`[FIRST HALF] ${key} : ${value}`)
: console.log(`[SECOND HALF] ${key} : ${value}`);
}