Created
September 3, 2021 07:06
-
-
Save misterpoloy/5b8354bc0090b62f267ffaa9a3d9a1e8 to your computer and use it in GitHub Desktop.
Count match winner
This file contains hidden or 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
| 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
commented
Sep 3, 2021
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment