SORT¶
Description¶
SORT will sort the elements in a list.
It works on numbers as well as on text.
If a string starts with a number will come before strings starting with letters.
Given a field name as a second argument, SORT orders a list of dictionaries by that field instead, as in
SORT(people, 'age').
Every element then has to be a dictionary, so this cannot order instances.
Also see sort(), which takes a key it computes for each element instead of a field name.
Example: Numbers¶
This will return [1, 5, 76].
Example: Text¶
The sorting will return ['Anna', 'Annabelle', 'Benjamin', 'Laura'], which is then reversed, so the whole expression
returns ['Laura', 'Benjamin', 'Annabelle', 'Anna']
Example: Text with Numbers¶
In this example, one string starts with a number.
It will therefore come before the strings starting with letters, so this expression will return ['101 Dalmatians',
'Aladdin', 'Snow White'].
Unknown values¶
Info
New in Atfinity 17.
A value that is unknown is ordered after every known value, so SORT(['Benjamin', unknown, 'Anna']) returns
['Anna', 'Benjamin', unknown].
Given a field name, an element is ordered last in the same way when its field is unknown, when the field is missing
from it, and when the element is itself unknown.
The known values still have to be comparable with each other, so sort numbers with numbers and text with text.