Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 2a350a0

Browse files
committed
feat: Coding Challenge 3 of DS and Modern Operators Done
1 parent d057887 commit 2a350a0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

challenges/section09-challenge.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,44 @@ let scorersMsg = 'Scorers';
164164
for (let [key, value] of Object.entries(scorers))
165165
scorersMsg = scorersMsg.concat(`\n${ key }: ${ value }`);
166166
console.log(scorersMsg);
167+
168+
// Coding Challenge 3
169+
170+
/*
171+
1. Create an array 'events' of the different game events that happened(no
172+
duplicates);
173+
2. After the game has finished, is was found that the yellow card from minute 64
174+
was unfair.So remove this event from the game events log.
175+
3. Compute and log the following string to the console: "An event happened, on;
176+
average, every 9 minutes" (keep in mind that a game has 90 minutes);
177+
4. Loop over 'gameEvents' and log each element to the console, marking
178+
whether it's in the first half or second half (after 45 min) of the game, like this:
179+
[FIRST HALF]17:
180+
⚽ GOAL;
181+
*/
182+
183+
const gameEvents = new Map([
184+
[17, '⚽ GOAL'],
185+
[36, '🔁 Substitution'],
186+
[47, '⚽ GOAL'],
187+
[61, '🔁 Substitution'],
188+
[64, '🔶 Yellow card'],
189+
[69, '🔴 Red card'],
190+
[70, '🔁 Substitution'],
191+
[72, '🔁 Substitution'],
192+
[76, '⚽ GOAL'],
193+
[80, '⚽ GOAL'],
194+
[92, '🔶 Yellow card'],
195+
]);
196+
console.log(gameEvents);
197+
198+
const uniqueEvents = new Set([...gameEvents.values()]);
199+
console.log(uniqueEvents);
200+
201+
gameEvents.delete(64);
202+
console.log(gameEvents);
203+
204+
console.log(`An event happened, on average, every ${ 90 / gameEvents.size } minutes`);
205+
206+
for (let [key, value] of gameEvents)
207+
console.log(`[${ key <= 45 ? 'FIRST' : 'SECOND' } HALF] ${ key }: ${ value }`);

0 commit comments

Comments
 (0)