Created
August 16, 2019 11:48
-
-
Save anthify/218ec222328d6ac3f613700f5cd9b808 to your computer and use it in GitHub Desktop.
Clue for Premier League Challenge...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let prem = {}; | |
const tallyMatch = ({ team1, team2, score1, score2 }) => { | |
// Check to see if the `prem` object | |
// contains the team yet, and if not add it. | |
if (!prem[team1.name]) { | |
prem[team1.name] = { points: 0, name: team1.name }; | |
} | |
if (!prem[team2.name]) { | |
prem[team2.name] = { points: 0, name: team2.name }; | |
} | |
// if a tie | |
if (score1 === score2) { | |
prem = { | |
...prem, | |
[team1.name]: { | |
...prem[team1.name], | |
points: prem[team1.name].points + 1 | |
}, | |
[team2.name]: { | |
...prem[team2.name], | |
points: prem[team2.name].points + 1 | |
} | |
}; | |
return; | |
} | |
// a win for team1 | |
if (score1 > score2) { | |
prem = { | |
...prem, | |
[team1.name]: { | |
...prem[team1.name], | |
points: prem[team1.name].points + 3 | |
} | |
}; | |
} else { | |
// a win for team2 | |
prem = { | |
...prem, | |
[team2.name]: { | |
...prem[team2.name], | |
points: prem[team2.name].points + 3 | |
} | |
}; | |
} | |
}; | |
data.rounds.forEach(round => round.matches.forEach(tallyMatch)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment