JavaScript/jQuery: colMax()

Retrieve max value of a given column of table cells:

function colMax(parent, colIndex) {
var max = 0,
sorted = $(‘td:nth-child(’ + colIndex + ‘)’, parent).get().sort(function(a, b) {
return b - a;
});

max = parseInt(sorted.length > 0 ? $(sorted[sorted.length - 1]).text() : 0);

return !isNaN(max) ? max : 0;
}

var max = colMax($(‘.table tbody’)[0], 1);

  1. Using the cell parent, get and sort the cells.
  2. Check length and return top cell.

Following

  • the-absolute-funniest-posts
  • funniest10k
  • mikelernerphotography
  • attentionindustry
  • tastefullyoffensive
  • evangotlib
  • infoneer-pulse
  • merlin
  • poplipps
  • cavalier
  • redshooter
  • frezned
  • amyvernon
  • minimalistco
  • theclearlydope
  • deviantart
  • yagottabelieve
  • mashable
  • poptech
  • gregbabula
  • john
  • teaim
  • despicablealexis
  • purple-lightsaber
  • toptumbles
  • hellonewyork
  • nonprofit-design
  • plus5mace
  • wantful
  • pixel2html
  • adobegripes
  • kimjongillookingatthings
  • tuneage
  • mikehudack
  • sirmitchell
  • officialbeastieboys
  • wondertonic
  • jordanwaller
  • badassjs
  • iiiil0liiii
  • fuzzythinking
  • manxmidge
  • rosskempfolds
  • londonelek
  • bigpinots
  • hoveringartdirectors