Skip to content

Instantly share code, notes, and snippets.

@barce
Created May 30, 2014 18:04
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 barce/4f31142aaff493cb433e to your computer and use it in GitHub Desktop.
Save barce/4f31142aaff493cb433e to your computer and use it in GitHub Desktop.
load jquery in console and get average age from a table
var jq = document.createElement('script');
jq.src = "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
// get average age from this table: http://www.tdcj.state.tx.us/death_row/dr_executed_offenders.html
var ages = [],
sum = 0;
jQuery('tr').each(function(a,b) {
var age = jQuery(b).find('td:nth-child(7)').text();
if (age !== '') {
ages.push(age);
sum += parseInt(age);
}
});
console.log(sum / ages.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment