Syntax | sort anArray using <expression with element and nextElement> | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Semantics | sort allows you to sort an array by using an expression to compare array elements with each other. The sort algorithm will call the expression each time two elements need to be compared. The expression can return:
It is not determined, what sort algorithm will actually be used, though a Quicksort derivative is the most common. | |||||||||||||
Substitutables | anArray | Can be any variable or object attribute having the type Array. | ||||||||||||
<expression with element and next element> | This expression must use the currently evaluated array element and its next neighbor and indicates if the current order is ok or not. | |||||||||||||
Examples | // sort an array of integers in ascending order set sorted = sort myList using element - nextElement; //sort an array of strings in ascending order set sorted = sort myList using element.text < nextElement.text; //sort an array using dates in descending set sorted = sort myList using element.date > nextElement.date; // sort an array using boolean return values set sorted = sort myList using element <= nextElement; // sort an array with complex elements over 2 sort key set sorted = sort inputContainer.elements using (element.aString = nextElement.aString and element.anInteger < nextElement.anInteger) or element.aString < nextElement.aString; |
Overview
Content Tools