JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.rawgit.com/lodash/lodash/3.10.1/lodash.min.js"></script>
<ul id="unmatched">
</ul>
<ul id="aggregateInfo"></ul>
<ul id="matches">
</ul>
CSS
.team0 {
background-color: #FF9999;
}
.team1 {
background-color: #9999FF;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
margin-top: 10px;
}
table {
border-collapse: collapse;
}
th {
font-weight: normal;
background-color: #CCCCCC;
padding: 3px;
padding-right: 5px;
}
td {
padding: 3px;
}
JavaScript
var totalPlayers = 1000;
function isOnTeam1(index) {
if (index == 2) return false;
else if (index < 2) return (index % 2 === 0);
return (--index % 2 === 0);
}
//Copy pasta random algo
var randomSeed = 12345;
function random() {
var x = Math.sin(randomSeed++) * 10000;
return x - Math.floor(x);
}
function getMatches(playerCollection)
{
/*
playerCollection consists of Player objects with the properties:
.mmrQm (Quick Match MMR)
.mmrHl (Hero League MMR)
.gamesQm (Number of Quick Match Games)
.gamesHl (Number of Hero League Games)
.role (Random string out of [Assassin, Support, Specialist, Warrior]
.ranged (Boolean value, true = ranged hero, false = melee hero)
*/
var matches = [];
/* expected output:
array containing any amount of matches
containing array of 2 teams
containing array of 5 players
matches[matchIndex(0,n)][teamIndex(0,1)][playerIndex(0,4)]
*/
var nubPartitions = _(playerCollection)
.sortByOrder('mmrHl', ['desc'])
.reduce(function (acc, nub) {
if (nub.gamesHl <= 20) acc.placement.push(nub);
else if (nub.gamesHl > 20 && nub.gamesHl <= 50) acc.scrubClub.push(nub);
else if (nub.gamesHl > 50 && nub.gamesHl <= 125) acc.semi.push(nub);
else if (nub.gamesHL > 125 && nub.gamesHl <= 250) acc.am.push(nub);
else acc.pro.push(nub);
return acc;
}, { placement: [], scrubClub: [], semi: [], am: [], pro: [] })
matches = _([])
.concat(nubPartitions.pro, nubPartitions.am, nubPartitions.semi, nubPartitions.scrubClub, nubPartitions.placement)
.chunk(10)
.reduce(function (acc, batch) {
var teams = _(batch)
.reduce(function (acc, nub, index) {
if (isOnTeam1(index)) {
acc.team1.push(nub);
}
else {
...