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
UNIQUE
Daniel Gorman edited this page May 21, 2019
·
3 revisions
UNIQUE
returns an array of unique values taken from the source array.
UNIQUE(arg1)
-
arg1
is an array of values
Let's say we're given a response with some vehicle information that looks like this:
{
"data":{
"makes":[
"Toyota",
"BMW",
"Mercedes Benz",
"Toyota",
"BMW",
"Mercedes Benz"
],
"vehicles":[
{
"make":"Mercedes Benz",
"year":2000
},
{
"make":"BMW",
"year":2002
},
{
"make":"Mercedes Benz",
"year":2000
}
]
}
}
If we are only interested in which makes appear, and not their frequency or any other information, we could simply write the following:
UNIQUE(data.makes)
Which returns ["BMW", "Mercedes Benz", "Toyota"]
.
UNIQUE(data.vehicles) => [{"make":"BMW", "year":2002}, {"make":"Mercedes Benz", "year":2000}]
UNIQUE({{1, 2, 3, 4, 3}, {1, 2, 3, 4, 3}}) => [1, 2, 3, 4, 3]
UNIQUE
can determine uniqueness across all basic types, including integers
, strings
, floats
, and booleans
, but it can also determine uniqueness between complex data structures like hashes, sets, and arrays.