Last active
July 5, 2020 17:58
-
-
Save jhonnymoreira/74ea0033c79342f131c39f33fa72fa64 to your computer and use it in GitHub Desktop.
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
const RANKS_WEIGHTS = { | |
'Iron 1': 1, | |
'Iron 2': 2, | |
'Iron 3': 3, | |
'Bronze 1': 4, | |
'Bronze 2': 5, | |
'Bronze 3': 6, | |
'Silver 1': 7, | |
'Silver 2': 8, | |
'Silver 3': 9, | |
'Gold 1': 10, | |
'Gold 2': 11, | |
'Gold 3': 12, | |
'Platinum 1': 13, | |
'Platinum 2': 14, | |
'Platinum 3': 15, | |
'Diamond 1': 16, | |
'Diamond 2': 17, | |
'Diamond 3': 18, | |
'Immortal 1': 19, | |
'Immortal 2': 20, | |
'Immortal 3': 21, | |
Radiant: 22, | |
}; | |
const WEIGHTS_RANKS = { | |
1: 'Iron 1', | |
2: 'Iron 2', | |
3: 'Iron 3', | |
4: 'Bronze 1', | |
5: 'Bronze 2', | |
6: 'Bronze 3', | |
7: 'Silver 1', | |
8: 'Silver 2', | |
9: 'Silver 3', | |
10: 'Gold 1', | |
11: 'Gold 2', | |
12: 'Gold 3', | |
13: 'Platinum 1', | |
14: 'Platinum 2', | |
15: 'Platinum 3', | |
16: 'Diamond 1', | |
17: 'Diamond 2', | |
18: 'Diamond 3', | |
19: 'Immortal 1', | |
20: 'Immortal 2', | |
21: 'Immortal 3', | |
22: 'Radiant', | |
}; | |
const getAverageRank = (ranks) => | |
Math.round( | |
ranks.reduce( | |
(total, currentRank) => RANKS_WEIGHTS[currentRank] + total, | |
0 | |
) / ranks.length | |
); | |
const setUnrankedRanks = (ranks) => { | |
const unrankeds = ranks.filter((rank) => rank === '?'); | |
const rankeds = ranks.filter((rank) => rank !== '?'); | |
unrankeds.forEach(() => { | |
rankeds.push(WEIGHTS_RANKS[getAverageRank(rankeds)]); | |
}); | |
return rankeds; | |
}; | |
const getDetailedAverageRank = ({ allies, enemies }) => { | |
const normalizedAllies = setUnrankedRanks(allies); | |
const normalizedEnemies = setUnrankedRanks(enemies); | |
const alliesAverageRank = getAverageRank(normalizedAllies); | |
const enemiesAverageRank = getAverageRank(normalizedEnemies); | |
const matchAverageRank = getAverageRank([ | |
...normalizedAllies, | |
...normalizedEnemies, | |
]); | |
return { | |
allies: WEIGHTS_RANKS[alliesAverageRank], | |
enemies: WEIGHTS_RANKS[enemiesAverageRank], | |
match: WEIGHTS_RANKS[matchAverageRank], | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions
Allies and enemies should be listed as mentioned in here. Unranked players should be listed as
'?'
.Usage
generate-average-ranks.js