Skip to content

Instantly share code, notes, and snippets.

@misterpoloy
Created September 3, 2021 07:06
Show Gist options
  • Select an option

  • Save misterpoloy/5b8354bc0090b62f267ffaa9a3d9a1e8 to your computer and use it in GitHub Desktop.

Select an option

Save misterpoloy/5b8354bc0090b62f267ffaa9a3d9a1e8 to your computer and use it in GitHub Desktop.
Count match winner
function tournamentWinner(competitions, results) {
// Write your code here.
let maxWinnerCounter = Number.MIN_VALUE
let maxWinnerKey = ""
const resultsCounter = {};
console.log("bacon", results);
for (let i = 0; i < results.length; i++) {
const winnerKey = results[i] ? competitions[i][0] : competitions[i][1]
console.log("winnerKey", winnerKey);
// store counter
if (!resultsCounter[winnerKey]) resultsCounter[winnerKey] = 0
resultsCounter[winnerKey] = resultsCounter[winnerKey] + 1
// Check max winner
if (resultsCounter[winnerKey] > maxWinnerCounter) {
maxWinnerKey = winnerKey;
maxWinnerCounter = resultsCounter[winnerKey];
}
}
return maxWinnerKey;
}
// Do not edit the line below.
exports.tournamentWinner = tournamentWinner;
@misterpoloy

Copy link
Copy Markdown
Author

Uploading screenshot.png…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment