Custom Numeric Comparison for the Array.Sort Method : Array : Language Basics JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Language Basics » Array »

 

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 (59463121731
    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>
           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Language Basics
» Array