We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d2abe01 commit ba609f6Copy full SHA for ba609f6
1366-rank-teams-by-votes.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * @param {string[]} votes
3
+ * @return {string}
4
+ */
5
+const rankTeams = function(votes) {
6
+ if (votes.length === 1) return votes[0];
7
+ const score = new Map(votes[0].split('').map(c => [c, new Array(votes[0].length).fill(0)]));
8
+ for (s of votes) {
9
+ for (let i = 0; i < s.length; i++) {
10
+ score.get(s[i])[i]++;
11
+ }
12
13
+ return votes[0].split('').sort((a,b) => {
14
+ for (let i = 0; i < votes[0].length; i++) {
15
+ if (score.get(a)[i] > score.get(b)[i]) return -1;
16
+ if (score.get(a)[i] < score.get(b)[i]) return 1;
17
18
+ return a < b ? -1 : 1;
19
+ }).join('');
20
+};
0 commit comments