- Sets
- Maps : Fundamental
- Maps : Iteration
<script>
const game = {
team1: 'Bayern Munich',
team2: 'Borrussia Dortmund',
players: [
[
'Never',
'Pavard',
'Martinez',
'Alaba',
'Davies',
'Kimmich',
'Goretzka',
'Coman',
'Muller',
'Gnarby',
'Lewandowski',
],
[
'Burki',
'Schulz',
'Hummels',
'Akanji',
'Hakimi',
'Weigl',
'Witsel',
'Hazard',
'Brandt',
'Sancho',
'Gotze',
],
],
score: '4:0',
scored: ['Lewandowski','Gnarby','Lewandowski','Hummels'],
date: 'Nov 9th, 2037',
odds: {
team1: 1.33,
x: 3.25,
team2: 6.5,
},
};
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. having what events happened
const events = [...new Set(gameEvents.values())];
console.log(events);
//2. delete 64mins event
gameEvents.delete(64);
//3. Print the following string to the console: "An event happened, on everage, every 9 minutes"
console.log(`An event happened, on everage, every ${90/gameEvents.size} minutes`);
const time = [...gameEvents.keys()].pop(); //in the past, we used pop to delete last element, we could take advantage of it
console.log(time);
console.log(`An event happened, on everage, every ${time/gameEvents.size} minutes`);
//4.
for (const [min, event] of gameEvents) {
const half = min<=45? 'First':'Second';
console.log(`[${half}Half ${min}: ${event}]`);
}
</script>