Skip to content

Instantly share code, notes, and snippets.

@RANUX
Created July 23, 2016 09:51
Show Gist options
  • Save RANUX/f06dd874fb4fc00a015935a38169b51b to your computer and use it in GitHub Desktop.
Save RANUX/f06dd874fb4fc00a015935a38169b51b to your computer and use it in GitHub Desktop.
JQuery parse ul li table and count stats
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