The collection.sort( ) method sorts the elements of the original collection and also returns the sorted collection.
Note: This method modifies the original collection.
If collection.sort( ) is called with no parameters, only scalar values (number, text, date, booleans) are sorted. Elements are sorted by default in ascending order, according to their type.
If you want to sort the collection elements in some other order or sort any type of element, you must supply in methodName a comparison method that compares two values and returns true in $1.result if the first value is lower than the second value. You can provide additional parameters to methodName if necessary.
- methodName will receive the following parameters:
- $1 (object), where:
- $1.value (any type): first element value to be compared
- $1.value2 (any type): second element value to be compared
- $2...$N (any type): extra parameters
- methodName sets the following parameter:
- $1.result (boolean): true if $1.value < $1.value2, false otherwise
If the collection contains elements of different types, they are first grouped by type and sorted afterwards. Types are returned in the following order:
- null
- booleans
- strings
- numbers
- objects
- collections
- dates
C_OBJECT($1)
$1.result:=String($1.value)<String($1.value2)