Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
Daniel Gorman edited this page May 21, 2019 · 3 revisions

The UNIQUE Function

Function Group: Collection

UNIQUE returns an array of unique values taken from the source array.

Syntax

UNIQUE(arg1)

  • arg1 is an array of values

Uses

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"].

Other Examples

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]

Notes

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.

Clone this wiki locally