Created
July 23, 2016 09:51
-
-
Save RANUX/f06dd874fb4fc00a015935a38169b51b to your computer and use it in GitHub Desktop.
JQuery parse ul li table and count stats
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 items = []; | |
$('.history-table>ul>li>.td-likes').each(function(item) { | |
// clean spaces | |
var itemText = $(this).text().replace(/\s+/g, ' '); | |
itemText = itemText.replace(/^0\s$/g, '').split(/\s/g,2); | |
var num = parseInt(itemText); | |
if (num && !isNaN(num)) | |
items.push(num); | |
}); | |
var sum = 0; | |
var maxItem = 0; | |
items.forEach(function(item){ | |
sum += item; | |
maxItem = maxItem < item ? item : maxItem; | |
}); | |
console.log('Average: '+sum/items.length); | |
console.log('Max: '+maxItem); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment