Comparison Function in Javascript

This function is a simple comparison in order to sort an array based on high to low rather than the default low to high.

	
function mycomparator(a,b) {

	  return parseInt(a) - parseInt(b);

}

//Use this with a sort function
onSaleThisWeek.sort(mycomparator);

Related Post