This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
SORT
Daniel Gorman edited this page May 21, 2019
·
3 revisions
SORT
sorts a collection by the values returned from applying a sorting function to each element in said collection.
SORT(arg1, arg2)
-
arg1
is a collection -
arg2
is the sorting function that will be applied to each element of the collection
Let's say we're given a response with some vehicle information that looks like this:
{
"data":{
"fleet_prices":[16000, 17450, 9200],
"fleet_names": ["BMW", "Audi", "Mercedes Benz"]
}
}
If we want to organize those prices by basic numerical value, we can use SORT
with the dynamic references themselves serving as a sorting function:
SORT(data.fleet_prices, _)
This would return [9200, 16000, 17450]
.
We can also sort strings with that technique, as shown below:
SORT(data.fleet_names, _) => ["Audi", "BMW", "Mercedes Benz"]
We can also apply a function to the dynamic reference, as so:
SORT(data.fleet_names, LEN(_)) => ["Mercedes Benz", "Audi", "BMW",]