# Arrays and list functions

Use these functions to make interaction with arrays, lists, and strings easier.

## Distinct

The `distinct` function is used to get values from an array or list with duplicate values removed.

Format

``````{%= distinct(array) %}
``````

Example

The following operation specifies people who have placed orders in more than one store.

``````{%= distinct(person.orders.storeId).count() > 1 %}
``````

The `head` function is used to return the first item in the array or list.

Format

``````{%= head({array}) %}
``````

Example

The following operation returns the first of the top five orders with the highest price. More information about the `topN` function can be found in the first `n` in array section.

``````{%= head(topN(orders,price, 5)) %}
``````

## First `n` in array

The `topN` function is used to return the first `N` items in an array, when sorted in ascending order based on the given numerical expression.

Format

``````{%= topN(array, value, amount) %}
``````
Argument Description
`{ARRAY}` The array or list that is to be sorted.
`{VALUE}` The property in which to sort the array or list.
`{AMOUNT}` The number of items to be returned.

Example

The following operation returns the top five orders with the highest price.

``````{%= topN(orders,price, 5) %}
``````

## In

The `in` function is used to determine if an item is a member of an array or list.

Format

``````{%= in(value, array) %}
``````

Example

The following operation defines people with birthdays in March, June, or September.

``````{%= in (person.birthMonth, [3, 6, 9]) %}
``````

## Includes

The `includes` function is used to determine if an array or list contains a given item.

Format

``````{%= includes(array,item) %}
``````

Example

The following operation defines people whose favorite color includes red.

``````{%= includes(person.favoriteColors,"red") %}
``````

## Intersects

The `intersects` function is used to determine if two arrays or lists have at least one common member.

Format

``````{%= intersects(array1, array2) %}
``````

Example

The following operation defines people whose favorite colors include at least one of red, blue, or green.

``````{%= intersects(person.favoriteColors,["red", "blue", "green"]) %}
``````

## Last `n` in array

The `bottomN` function is used to return the last `N` items in an array, when sorted in ascending order based on the given numerical expression.

Format

``````{%= bottomN(array, value, amount) %}
``````
Argument Description
`{ARRAY}` The array or list that is to be sorted.
`{VALUE}` The property in which to sort the array or list.
`{AMOUNT}` The number of items to be returned.

Example

The following operation returns the top five orders with the lowest price.

``````{%= bottomN(orders,price, 5) %}
``````

## Not in

The `notIn` function is used to determine if an item is not a member of an array or list.

NOTE

The `notIn` function also ensures that neither value is equal to null. Therefore, the results are not an exact negation of the `in` function.

Format

``````{%= notIn(value, array) %}
``````

Example

The following operation defines people with birthdays that are not in March, June, or September.

``````{%= notIn(person.birthMonth ,[3, 6, 9]) %}
``````

## Subset of

The `subsetOf` function is used to determine if a specific array (array A) is a subset of another array (array B). In other words, that all elements in array A are elements of array B.

Format

``````{%= subsetOf(array1, array2) %}
``````

Example

The following operation defines people who have visited all of their favorite cities.

``````{%= subsetOf(person.favoriteCities,person.visitedCities) %}
``````

## Superset of

The `supersetOf` function is used to determine if a specific array (array A) is a superset of another array (array B). In other words, that array A contains all elements in array B.

Format

``````{%= supersetOf(array1, array2) %}
``````

Example

The following operation defines people who have eaten sushi and pizza at least once.

``````{%= supersetOf(person.eatenFoods,["sushi", "pizza"] %}
``````