We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ba609f6 commit c7798efCopy full SHA for c7798ef
1366-rank-teams-by-votes.js
@@ -1,3 +1,32 @@
1
+/**
2
+ * @param {string[]} votes
3
+ * @return {string}
4
+ */
5
+const rankTeams = function(votes) {
6
+ const hash = {}
7
+ const l = votes[0].length
8
+ for(let vote of votes) {
9
+ for(let i = 0; i < l; i++) {
10
+ const ch = vote[i]
11
+ if(hash[ch] == null) hash[ch] = Array(l).fill(0)
12
+ hash[ch][i]++
13
+ }
14
15
+ const keys = Object.keys(hash)
16
+ keys.sort((a, b) => {
17
18
+ if(hash[a][i] !== hash[b][i]) {
19
+ return hash[b][i] - hash[a][i]
20
21
22
+ return a === b ? 0 : (a < b ? -1 : 1)
23
+ })
24
+
25
+ return keys.join('')
26
+};
27
28
+// another
29
30
/**
31
* @param {string[]} votes
32
* @return {string}
0 commit comments