Sorting with Custom Algorithms : Sort : Array Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Array » Sort »

 

Sorting with Custom Algorithms


 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var aWords:Array = ["o""S""a""C"];
        aWords.sort(sorter);
        trace(aWords.toString());
    }
        function sorter(a:String, b:String):Number {
          if(a.toUpperCase() > b.toUpperCase()) {
            return -1;
          }
          else if(a.toUpperCase() < b.toUpperCase()) {
            return 1;
          }
          else {
            return 0;
          }
        }
  }
}
S,o,C,a

        



Leave a Comment / Note


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


Flash / Flex / ActionScript examples

 Navioo Array
» Sort