Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Dec 1, 2023
1 parent e1710bb commit 79b0ebd
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function tournamentWinner(competitions, results) {
let teams = new Map();
let maxPoints = 0;
let winner;

for (let index = 0; index < competitions.length; index++) {
let competition = competitions[index];
let result = results[index];
let team = result === 1 ? competition[0] : competition[1];

teams.set(team, (teams.get(team) || 0) + 3);
}

for (let [team, points] of teams.entries()) {
if (points > maxPoints) {
winner = team;
maxPoints = points;
}
}

return winner;
}

0 comments on commit 79b0ebd

Please sign in to comment.