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
Related examples in the same category