Skip to content

Instantly share code, notes, and snippets.

@qsysmine
Last active November 9, 2018 19:36
Show Gist options
  • Save qsysmine/c82579ef6366986727b0c6a16ad835a5 to your computer and use it in GitHub Desktop.
Save qsysmine/c82579ef6366986727b0c6a16ad835a5 to your computer and use it in GitHub Desktop.
Chrome terminal string for calculating Yahoo Fantasy basketball standings given `var matchupList = "{{LIST ID}}";`
var $list = document.getElementById(matchupList),
$matchups = $list.children,
matchups = [];
[].slice.call($matchups).forEach(function($matchup) {
var $matchupChildren = $matchup.children;
[].slice.call($matchupChildren).forEach(function($matchup) {
if([].slice.call($matchup.children).length < 2) return;
var matchup = [];
var $m0 = $matchup.children[0];
var $m1 = $matchup.children[1];
[$m0, $m1].forEach(function($m,i) {
var name = $m.children[0].children[1].children[0].children[i].children[0].innerText;
var matchupScore = $m.children[0].children[0].innerText;
var record = $m.children[0].children[1].children[0].children[i].children[1].innerText.split("|")[0].trim();
matchup.push({name: name, matchupScore: matchupScore, record: record})
});
matchups.push(matchup);
});
});
var evaluate = function(matchup) {
var mT = 13 - (parseInt(matchup[0].matchupScore) + parseInt(matchup[1].matchupScore));
var matchupRecord = matchup.map(function(matchupMember, i) {
var record = matchupMember.record,
matchupScore = parseInt(matchupMember.matchupScore),
currStats = {record: record, matchupScore: matchupScore},
w = parseInt(record.split("-")[0]),
l = parseInt(record.split("-")[1]),
t = parseInt(record.split("-")[2]);
var newW = w + matchupScore;
var newL = l + parseInt(matchup[1 - i].matchupScore);
var newT = t + mT;
return {w: newW, l: newL, t: newT, currStats: currStats, name: matchupMember.name};
});
return matchupRecord;
};
console.log((function() { var allTeams = []; matchups.map(evaluate).forEach(function(matchup) {matchup.forEach(function(team) {allTeams.push(team);});}); return allTeams.sort(function(a, b) {return b.w == a.w ? a.l - b.l : b.w - a.w});})())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment