Skip to content

Commit f4650f5

Browse files
committed
finish chalenge jonasschmedtmann#3 in 09
1 parent f2d2c25 commit f4650f5

File tree

1 file changed

+45
-2
lines changed
  • 09-Data-Structures-Operators/starter

1 file changed

+45
-2
lines changed

09-Data-Structures-Operators/starter/script.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,49 @@ GOOD LUCK 😀
156156

157157
// 1. Loop over the game.scored array and print each player name to the console, along with the goal number (Example: "Goal 1: Lewandowski")
158158

159-
for(let [index, k] of game.scored.entries()){
160-
console.log(`Goal ${index + 1}: ${k}`);
159+
// for(let [index, k] of game.scored.entries()){
160+
// console.log(`Goal ${index + 1}: ${k}`);
161+
// }
162+
163+
///////////////////////////////////////
164+
// Coding Challenge #3
165+
166+
/*
167+
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).
168+
169+
1. Create an array 'events' of the different game events that happened (no duplicates)
170+
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.
171+
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)
172+
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:
173+
[FIRST HALF] 17: ⚽️ GOAL
174+
175+
GOOD LUCK 😀
176+
*/
177+
178+
const gameEvents = new Map([
179+
[17, '⚽️ GOAL'],
180+
[36, '🔁 Substitution'],
181+
[47, '⚽️ GOAL'],
182+
[61, '🔁 Substitution'],
183+
[64, '🔶 Yellow card'],
184+
[69, '🔴 Red card'],
185+
[70, '🔁 Substitution'],
186+
[72, '🔁 Substitution'],
187+
[76, '⚽️ GOAL'],
188+
[80, '⚽️ GOAL'],
189+
[92, '🔶 Yellow card'],
190+
]);
191+
192+
// 1. Create an array 'events' of the different game events that happened (no duplicates)
193+
const events = [...new Set([...gameEvents.values()])];
194+
console.log(events);
195+
196+
// 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.
197+
gameEvents.delete(64);
198+
console.log(gameEvents);
199+
200+
// 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
201+
for(const [k, v] of gameEvents.entries()){
202+
let r = k < 45 ? "FIRST HALF" : "SECOND HALF";
203+
console.log(`[${r}] ${k}: ${v}`);
161204
}

0 commit comments

Comments
 (0)