UNIQUE

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.

Syntax

UNIQUE(arg1)

Arguments

Description

arg1

Array of values.

Examples

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
}
]
}
}

Example 1: Find unique vehicle manufacturers

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 manufacturers
UNIQUE(data.makes)
# Returns ["BMW", "Mercedes Benz", "Toyota"]

Example 2: Find unique vehicles

In this example, we are looking for unique vehicles.

# Identify unique vehicles
UNIQUE(data.vehicles)
# Returns [{"make":"BMW", "year":2002},
# {"make":"Mercedes Benz", "year":2000}
# ]

Example 3: Find unique number set

In this example, we are looking for a unique set of numbers.

# Identify unique sets of numbers
UNIQUE({{1, 2, 3, 4, 3}, {1, 2, 3, 4, 3}})
# Returns [1, 2, 3, 4, 3]