Skip to content

Instantly share code, notes, and snippets.

@zeroasterisk
Last active May 3, 2017 14:57
Show Gist options
  • Save zeroasterisk/5d9478c3865a4b931a6347478d162af8 to your computer and use it in GitHub Desktop.
Save zeroasterisk/5d9478c3865a4b931a6347478d162af8 to your computer and use it in GitHub Desktop.
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 [email protected]',
'Bowman Isaac [email protected]',
'Childs Jamila [email protected]',
'Deaton Michael [email protected]',
'DeVore Rebekah [email protected]',
'Frost Travis [email protected]',
'Goldstein Neil [email protected]',
'Hammer Rebecca [email protected]',
'Hawley Mary [email protected]',
'Kessler Tracy [email protected]',
'Madariaga Cuba Lilian Maria [email protected]',
'Matheis Stephen [email protected]',
'Mudd Adam [email protected]',
'Noland Andrew [email protected]',
'Paul Roman [email protected]',
'Phillips Isis [email protected]',
'Richter Stephanie [email protected]',
'Robles Chris [email protected]',
'Sizemore John [email protected]',
'Viers Valerie [email protected]',
'Wilson Eric [email protected]',
];
var students_cj_shauvonm = [
'Bowman Robert [email protected]',
'Bushau Jeremiah [email protected]',
'Clark Stephanie [email protected]',
'DeSpain Patrick [email protected]',
'Duley Eric [email protected]',
'Glas Jennifer [email protected]',
'Hagood Emily [email protected]',
'Hansen Don [email protected]',
'Howard Andre [email protected]',
'Kiino Sarah [email protected]',
'Littrell Brian [email protected]',
'Martin Richard [email protected]',
'McCormick Melanie [email protected]',
'Nestmann Jason [email protected]',
'Paige Alex [email protected]',
'Peyton Matthew [email protected]',
'Pinkerton Tim [email protected]',
'Robbins Ethan [email protected]',
'Simone Matt [email protected]',
'Strecker Kurt [email protected]',
'Von Dwingelo Juanita [email protected]',
'Winters Charles [email protected]',
];
/**
* 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