Created
November 18, 2015 23:01
-
-
Save timReynolds/aa6baf745249321c723a to your computer and use it in GitHub Desktop.
Code dojo pairing names
This file contains 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 people = ["TT", "ME", "FE", "TR", "JE", "DE", "AD"]; | |
Array.prototype.group = group; | |
function group(size = 2, sizingFunc) { | |
const tmp = this.slice(); | |
const output = []; | |
while(tmp.length) { | |
const groupSize = sizingFunc(tmp.length, size); | |
output.push(tmp.splice(0, groupSize)); | |
} | |
return output; | |
} | |
function groupWithUndersize(remaining, size) { | |
return size; | |
} | |
function groupWithoutUndersize(remaining, size) { | |
return remaining % size ? size+1 : size; | |
} | |
function predefinedGroupNumber(originalGroupSize, roundFunc) { | |
return function(remaining, size) { | |
return roundFunc(originalGroupSize / size); | |
} | |
} | |
function randomSort() { | |
return 0.5 - Math.random(); | |
}; | |
var groups = people.sort(randomSort).group(3, predefinedGroupNumber(people.length, Math.ceil)); | |
console.log(groups); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment