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 79b0ebd commit 1b8e9aa
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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];
let points = (teams.get(team) || 0) + 3;

teams.set(team, points);

if (points > maxPoints) {
winner = team;
maxPoints = points;
}
}

return winner;
}

0 comments on commit 1b8e9aa

Please sign in to comment.