src/utilities/Sorter.js
function Sorter(comparator) {

    // the comparator is a private attribute so methods that use it are defined in the constructor
    comparator = comparator || new Comparator();

    this.sortCollection = function(collection) {
        if (collection && collection.getSize() > 1) {
            var array = collection.toArray();
            array = sortArray(comparator, array);
            collection.deleteAll();
            collection.addItems(array);
        }
    };

    return this;
}
function Sorter(comparator) {

    // the comparator is a private attribute so methods that use it are defined in the constructor
    comparator = comparator || new Comparator();

    this.sortCollection = function(collection) {
        if (collection && collection.getSize() > 1) {
            var array = collection.toArray();
            array = sortArray(comparator, array);
            collection.deleteAll();
            collection.addItems(array);
        }
    };

    return this;
}
function Sorter ( comparator ) { // the comparator is a private attribute so methods that use it are defined in the constructor comparator = comparator || new Comparator ( ) ; this . sortCollection = function ( collection ) { if ( collection && collection . getSize ( ) > 1 ) { var array = collection . toArray ( ) ; array = sortArray ( comparator , array ) ; collection . deleteAll ( ) ; collection . addItems ( array ) ; } } ; return this ; }
PUBLIC CONSTRUCTORS 
This sorter class implements a standard merge sort algorithm.  The collection to be sorted
is recursively split into two collections each of which are then sorted and then the two
collections are merged back into a sorted collection.

@constructor
@param {Comparator} comparator An optional comparator to be used when comparing items during
sorting. If none is specified, the natural comparator will be used.
PUBLIC CONSTRUCTORS This sorter class implements a standard merge sort algorithm . The collection to be sorted is recursively split into two collections each of which are then sorted and then the two collections are merged back into a sorted collection .