var teams = [];
var teamCount = 0;
var teamSize = 5;
var start, end;
var average = 0;
function myFunction() {
start = performance.now();
$("#myID").html('');
$("#dif1").html('');
$("#dif2").html('');
$("#dif3").html('');
elos = getElos();
console.log(elos.length);
teamCount = elos.length / teamSize;
teams.length = 0;
var i = 0;
average = elos.reduce(function(a, b) {
return Number(a) + Number(b);
});
average = average / elos.length;
//order default list of elos
elos.sort();
//add 1 high and 1 low elo to each team
for (i = 0; i < teamCount; i++) {
teams[i] = new Array();
teams[i][0] = elos.splice(0, 1);
teams[i][1] = elos.splice(elos.length - 1, 1);
}
//first sort by median elo
sortTeams();
$("#dif1").html(getMedian(teams[teams.length - 1]) - getMedian(teams[0]));
//add another high and another low elo to each team
for (i = teamCount - 1; i > -1; i--) {
teams[i][2] = elos.splice(0, 1);
teams[i][3] = elos.splice(elos.length - 1, 1);
}
//second sort by median elo
sortTeams();
$("#dif2").html(getMedian(teams[teams.length - 1]) - getMedian(teams[0]));
//add highest remaining elo to lowest median elo team
for (i = 0; i < teamCount; i++) {
teams[i][4] = elos.splice(elos.length - 1, 1);
}
//3rd and final sort by median elo
sortTeams();
$("#dif3").html(getMedian(teams[teams.length - 1]) - getMedian(teams[0]));
end = performance.now();
$("#time").html(end - start);
$('#average').html(average);
//display results
printTeams();
}
//sort each team by average elo
function sortTeams() {
teams.sort(function(a, b) {
a = getMedian(a);
b = getMedian(b);
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
return 0;
});
}
//get average elo of each team
function getMedian(numberArray) {
var sum = numberArray.reduce(function(a, b) {
return Number(a) + Number(b);
});
return (sum / teamSize);
}
//get largest team...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.