FEEL

sort

FEEL built-in function · FEEL list functions

sort(list, precedes)

Returns the list sorted by the precedes function.

The precedes function decides the order: it receives two elements and returns true if the first belongs before the second. To sort contexts, compare the field you want. To sort in descending order, use >.

DMN 1.6 lists both parameters without marking precedes optional. The engine behind this site also accepts sort(list) for comparable elements and sorts them ascending, but a portable model passes the function.

Parameters

ParameterTypeDescription
listlistthe list to sort
precedesfunctionordering function taking two elements and returning true if the first sorts before the second

Examples

sort([3, 1, 2], function(x, y) x < y)
[1, 2, 3] Try it ↑
sort(["b", "a", "c"], function(x, y) x < y)
[a, b, c] Try it ↑

Edge cases and null handling

sort([3, 1, 2], function(x, y) x > y)
[3, 2, 1] Try it ↑

Descending.

sort([{n: "b"}, {n: "a"}], function(x, y) x.n < y.n)
[{n=a}, {n=b}] Try it ↑

Sort contexts by a field.

Related functions

reverse

Defined by the OMG DMN 1.6 specification, chapter 10.3.4 (built-in functions).