1
var rankTeams = function (votes) {2
if (votes.length == 1) return votes[0];4
for (let vote of votes) {5
for (let i = 0; i < vote.length; i++) {6
if (!map.has(vote[i])) {7
//create all the values set as zero8
map.set(vote[i], Array(vote.length).fill(0));10
let val = map.get(vote[i]);12
map.set(vote[i], val);16
let obj = [...map.entries()]; //converting as array ["A",[5,0,0]]17
obj = obj.sort((a, b) => {18
for (let i = 0; i < a[1].length; i++) {19
if (a[1][i] > b[1][i]) return -1;20
else if (a[1][i] < b[1][i]) return 1;22
// if all chars are in same positon return the value charcode23
return a[0].charCodeAt(0) - b[0].charCodeAt(0);25
return obj.map((item) => item[0]).join("");