Skip to content

Instantly share code, notes, and snippets.

@bluej100
Created July 31, 2015 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluej100/5b28cf7065b07f0aa96f to your computer and use it in GitHub Desktop.
Save bluej100/5b28cf7065b07f0aa96f to your computer and use it in GitHub Desktop.
var headers = $('th.group0.valignmenttop');
var getCity = function(header) {
var rate_row = $(header.parentNode).nextAll().slice(0, header.getAttribute('rowSpan')-1).last();
return {name: header.textContent.trim(), violent: parseCell($(rate_row).find('.group3')), property: parseCell($(rate_row).find('.group8'))};
}
var parseCell = function(cell) {
return parseFloat(cell.text().replace(/[^\d.]/g, ''));
}
var cities = headers.toArray().map(getCity);
cities = cities.filter(function(city) {return !!city.violent && !!city.property;});
var rates = cities.map(function(city) {return city.violent;});
var average = average = rates.reduce(function(a, b) {return a+b;}) / rates.length;
// 360.539265536723
var slc = cities.find(function(city) {return city.name == 'Salt Lake City, UT M.S.A.';})
// Object { name: "Salt Lake City, UT M.S.A.", violent: 327.5, property: 4328 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment