Created
June 6, 2018 11:29
-
-
Save ville6000/b513f73fc54bc37eb9309ebae3040a7e to your computer and use it in GitHub Desktop.
MMArmy longest streaks
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
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