From http://ejohn.org/blog/fast-javascript-maxmin/