Custom Numeric Comparison for the Array.Sort Method
<HTML>
<HEAD>
<TITLE>
Numeric comparisons
</TITLE>
<HEAD>
<BODY>
<H1>
<SCRIPT>
function numSort(a,b){
return a - b;
}
var numArray = new Array (59, 4, 63, 12, 17, 3, 2 , 1)
document.write ("Original array: " + numArray);
document.write ("<br>");
document.write ("Default Sorted array: " + numArray.sort());
document.write ("<br>");
document.write ("Numerically sorted array: " +
numArray.sort(numSort));
</SCRIPT>
</H1>
</BODY>
</HTML>
Related examples in the same category