Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code Lou - FSJS - teams
/**
* Build a set of randomized, evenly distrubted teams
*
* goal team size = ~5 or 6
*
* usage:
* download file and save as make_class_teams.js
*
* $ node make_class_teams.js
*
* it should output information to the the console...
* BUT I am going to run and assign teams myself
* (feel free to run this for fun)
*/
var teamSize = 6;
var students_alan_aaron = [
'Barton Heather artzyone87@gmail.com',
'Bowman Isaac ilbowman40204@gmail.com',
'Childs Jamila mimichilds118@gmail.com',
'Deaton Michael mrdeaton123@gmail.com',
'DeVore Rebekah devore.rc@gmail.com',
'Frost Travis frost.travis@gmail.com',
'Goldstein Neil Neil.Goldstein06@gmail.com',
'Hammer Rebecca rehamm01@gmail.com',
'Hawley Mary margrahaw@gmail.com',
'Kessler Tracy starletawe@gmail.com',
'Madariaga Cuba Lilian Maria mclilian27@gmail.com',
'Matheis Stephen nickmath21@gmail.com',
'Mudd Adam acmudd02@yahoo.com',
'Noland Andrew anoland.lou@gmail.com',
'Paul Roman romanpaul@outlook.com',
'Phillips Isis isis_phillips@yahoo.com',
'Richter Stephanie StephanieDRichter@gmail.com',
'Robles Chris cjrobles2@gmail.com',
'Sizemore John guysizemore@me.com',
'Viers Valerie valerieviers@yahoo.com',
'Wilson Eric ewpiano@gmail.com',
];
var students_cj_shauvonm = [
'Bowman Robert rjbowman8@gmail.com',
'Bushau Jeremiah exjerlock@hotmail.com',
'Clark Stephanie steph.z.clark@gmail.com',
'DeSpain Patrick ptdespain@gmail.com',
'Duley Eric ericduley@yahoo.com',
'Glas Jennifer jenn@jennglas.com',
'Hagood Emily hagoodem@gmail.com',
'Hansen Don dhansen@area71.com',
'Howard Andre andre.howard40@yahoo.com',
'Kiino Sarah sarah.kiino@gmail.com',
'Littrell Brian brianl@bluegrass.net',
'Martin Richard thetvdoctor66@gmail.com',
'McCormick Melanie mtmccorm@gmail.com',
'Nestmann Jason nestmannj@bellsouth.net',
'Paige Alex apaige161@gmail.com',
'Peyton Matthew matthewcpeyton@gmail.com',
'Pinkerton Tim timpinkerton@mail.com',
'Robbins Ethan ethanrobbins@ymail.com',
'Simone Matt Matt.simone14@gmail.com',
'Strecker Kurt ksphotopro@gmail.com',
'Von Dwingelo Juanita jvondwingelo@gmail.com',
'Winters Charles destinydiver@gmail.com',
];
/**
* we want to split up the array into groups of size <chunksize>
* add a new prototype to all arrays in javascript
*/
Array.prototype.chunk = function (groupsize) {
var sets = [];
var chunks = this.length / groupsize;
for (var i = 0, j = 0; i < chunks; i++, j += groupsize) {
sets[i] = this.slice(j, j + groupsize);
}
return sets;
};
/**
* we want to randomize all parts of an array (shuffle items)
* add a new prototype to all arrays in javascript
* MUTATES array & returns it
*/
Array.prototype.shuffle = function(){
var counter = this.length, temp, index;
// While there are elements in the array
while (counter > 0) {
// Pick a random index
index = (Math.random() * counter--) | 0;
// And swap the last element with it
temp = this[counter];
this[counter] = this[index];
this[index] = temp;
}
// return this, so we can chain
return this;
};
// for our array - split it into teams of 5
[students_alan_aaron, students_cj_shauvonm].forEach(function(students, classIndex) {
console.log("------------------------------");
console.log("class #" + (classIndex + 1));
console.log("------------------------------");
students.shuffle().chunk(teamSize).forEach(function(team, index) {
console.log(" team #" + (index + 1));
team.forEach(function(name) {
console.log(" " + name);
});
});
console.log("");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment