List Processing (Part 3) – Sorting

ARRAY_SORT

Definition: ARRAY_SORT(Array $list, [$(item) comparator])

ARRAY_SORT will sort the given array by value. You may optionally give a lambda that will provide an alternate sort value, which is useful when you need to sort by key.

Example 1

LET $list := ARRAY(4, 6, 1, 5);

24 > ARRAY_SORT($list);

25

Example 2

Where $list :=

26

ARRAY_SORT($list, $(item) ARRAY_INDEX($item, 2)) evaluates to:

27

ARRAY_SORTDESC

Definition: ARRAY_SORT(Array $list, $(item) comparator)

This function is identical to ARRAY_SORT, except it will return the results in the reverse order.

Related Articles