class Test {
    static function main() {
        var array:Array<{i:Int, s:String}> = [
            {i:3, s:"SECOND"},
            {i:3, s:"THIRD"},
            {i:1,s:"FIRST"},
            {i:3, s:"FOURTH"}
        ];
        print("An Array with objects", array);
        
    var copy = array.copy();
        copy.sort(function(a, b) {
           if(a.i < b.i) return -1;
           else if(a.i > b.i) return 1;
           else return 0;
        });
        print("Sort with array.sort()", copy);
        
        
    var copy = array.copy();
        haxe.ds.ArraySort.sort(copy, function(a, b) {
           if(a.i < b.i) return -1;
           else if(a.i > b.i) return 1;
           else return 0;
        });
    print("Sort with haxe.ds.ArraySort.sort()", copy);
        
    }
    
    // a function to print the array
    static function print(msg:String, a:Array<{i:Int, s:String}>) {
        trace(msg);
        trace(a.map(function(obj) return '${obj.s}').join(", "));
        trace("");
    }

}