SortedBy |
Syntax |
SortedBy(L:LIST, F:FUNCTION):LIST where V is a variable containing a list and F is a boolean-valued comparison function of two arguments (e.g. representing less than). |
Description |
Example |
/**/ define ByLength(S, T) -- define the sorting function return Len(S) > Len(T); EndDefine; /**/ M := ["dog","mouse","cat"]; /**/ SortedBy(M, ByLength); ["mouse", "dog", "cat"] /**/ M; -- M is not changed ["dog", "mouse", "cat"] /**/ sorted(M); -- the function "Sort" sorts using the default ordering: -- in this case, alphabetical order. ["cat", "dog", "mouse"] /**/ SortBy(Ref M, ByLength); -- sort M in place, changing M /**/ M; ["mouse", "cat", "dog"] |
See Also |