SORT
SORT sorts a collection by the values returned from applying a sorting function to each element in the collection.
Function category: Collection

Syntax

SORT(arg1, arg2)
Argument
Description
arg1
A key function. Each element of the collection is passed to that function and then sorted based on the function's result. An underscore ( _ ) represents a placeholder, which is the value itself (dynamic reference).
arg2
A collection to be sorted.

Examples

Let's say we're given a response with the following vehicle information:
1
{
2
"data":{
3
"fleet_prices": [16000, 17450, 9200],
4
"fleet_names": ["BMW", "Audi", "Mercedes Benz"]
5
}
6
}
Copied!

Example 1: Sort prices by numerical value

If we want to organize these prices by basic numerical value, we can use SORT with the dynamic references themselves serving as a sorting function.
1
# Sort prices using dynamic references
2
SORT(_, data.fleet_prices)
3
4
# Returns [9200, 16000, 17450]
Copied!

Example 2: Sort strings using same arguments

We can also sort strings using SORT with dynamic references.
1
# Sort strings using dynamic references
2
SORT(_, data.fleet_names)
3
4
# Returns ["Audi", "BMW", "Mercedes Benz"]
Copied!

Example 3: Sort using a dynamic reference

We can also apply a function such as LEN to the dynamic reference. This sorts by length of string.
1
# Sort strings using the LEN function with dynamic references
2
SORT(LEN(_), data.fleet_names)
3
4
# Returns ["Mercedes Benz", "Audi", "BMW",]
Copied!
Last modified 1yr ago
Export as PDF
Copy link