Skip to content

Instantly share code, notes, and snippets.

@ville6000
Created June 6, 2018 11:29
Show Gist options
  • Save ville6000/b513f73fc54bc37eb9309ebae3040a7e to your computer and use it in GitHub Desktop.
Save ville6000/b513f73fc54bc37eb9309ebae3040a7e to your computer and use it in GitHub Desktop.
MMArmy longest streaks
var record = {
loss: 0,
win: 0
};
var lastResult = false;
var currentStreak = 0;
jQuery('.record').find('tr').each(function(idx, el) {
if (idx > 0) {
var row = jQuery(el);
var key = (row.find('td:first-child').hasClass('win') || row.find('td:first-child').hasClass('winTitle')) ? 'win' : 'loss';
if (lastResult === false) {
lastResult = key;
currentStreak++;
} else {
if (lastResult === key) {
currentStreak++;
} else {
lastResult = key
currentStreak = 1;
}
}
if (record[key] < currentStreak) {
record[key] = currentStreak;
}
}
});
console.log(record);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment