Call the sort( ) method passing the bandNameSort compare function : Sort : Array Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Array » Sort »

 

Call the sort( ) method passing the bandNameSort compare function


 


package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var bands:Array = ["C","W","L","T","A","r"];
                           
        bands.sort(bandNameSort);
        for(var i:int 0; i < bands.length; i++) {
            trace(bands[i]);
        }
        
        function bandNameSort(band1:String, band2:String):int{
            band1 = band1.toLowerCase(  );
            band2 = band2.toLowerCase(  );
            if(band1.substr(04== "the ") {
                band1 = band1.substr(4);
            }
            if(band2.substr(04== "the ") {
                band2 = band2.substr(4);
            }
            if(band1 < band2) {
                return -1;
            }
            else {
                return 1;
            }
        }
    }
  }
}

        



Leave a Comment / Note


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


Flash / Flex / ActionScript examples

 Navioo Array
» Sort