UNIQUE
returns an array of unique values taken from the source array.
Function category: Collection​
UNIQUE
can determine uniqueness across all basic types, including integer, string, floats and Boolean. It can also determine uniqueness between complex data structures like hashes, sets, and arrays.
UNIQUE(arg1)
Arguments | Description |
arg1 | Array of values. |
Let's say we're given a response with the following vehicle information:
{"data":{"makes":["Toyota","BMW","Dodge","Mercedes Benz","Ford","BMW","GM""Nissan"],"vehicles":[{"make":"Mercedes Benz","year":2000},{"make":"BMW","year":2002},{"make":"Mercedes Benz","year":2000}]}}
If we are only interested in identifying vehicle manufacturers, that is, the "make"
, and not its frequency or any other information, use the following.
# Identify vehicle manufacturersUNIQUE(data.makes)​# Returns ["BMW", "Mercedes Benz", "Toyota"]
In this example, we are looking for unique vehicles.
# Identify unique vehiclesUNIQUE(data.vehicles)​# Returns [{"make":"BMW", "year":2002},# {"make":"Mercedes Benz", "year":2000}# ]
In this example, we are looking for a unique set of numbers.
# Identify unique sets of numbersUNIQUE({{1, 2, 3, 4, 3}, {1, 2, 3, 4, 3}})​# Returns [1, 2, 3, 4, 3]