Created
March 1, 2012 16:07
-
-
Save tstone/1950861 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function choice(set, choice) { | |
return set.indexOf(choice) > -1 ? choice : ''; | |
} | |
function blankArray(l) { | |
return (new Array(l)).map(function(){ return ''; }); | |
} | |
Array.prototype.pairChoice = function(c) { | |
return this.pairs().map(function(pair) { return choice(pair, c); }); | |
}; | |
Array.prototype.elevate = function(team, step) { | |
var set = this | |
, i = set.indexOf(team); | |
if (typeof step === 'undefined') { step = set.length - 1; } | |
var loop = function(acc, set) { | |
var beyond = (acc + 1) > step | |
, l = set[acc].length; | |
if (l == 2) { return set.ipush(beyond ? blankArray(1) : [team]); } | |
return loop(acc + 1, set.ipush(beyond ? blankArray(l / 2) : set[acc].pairChoice(team) )); | |
}; | |
return loop(0, [set]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment