# Filtering

## ARRAY_WHERE

Definition: **ARRAY_ WHERE** **(**Array** $list, **$(i, item) **filter)**

**ARRAY_WHERE** is a filtering function. From your original list, you can eliminate items that do not match a given rule. To put it another way, it will only keep items that match the filter lambda.

### Example 1

This example will keep only items that are less than 5 ($item < 5). In this case only the numbers 1 to 4 are kept.

### Example 2

This example will keep only items are even numbers.

## ARRAY_DISTINCT

Definition: **ARRAY_DISTINCT(**Array** $list)**

**ARRAY_DISTINCT** is a more specific filtering function, that will remove any duplicate items in the original list.

# Sorting

## ARRAY_SORT

Definition: **ARRAY_SORT(**Array** $list, [**$(item)** comparator])**

**ARRAY_SORT** will sort the given array by value. You may optionally give a lambda that will provide an alternate sort value, which is useful when you need to sort by key.

### Example 1

LET $list := ARRAY(4, 6, 1, 5);

> ARRAY_SORT($lists)

### Example 2

LET $list := ARRAY( ARRAY(1, "Stuart"), ARRAY(2, "Kevin"), ARRAY(3, "Wei"), ARRAY(4, "Brendon) );

> ARRAY_SORT($list, $(i, item) ARRAY_INDEX($item, 2))

## ARRAY_SORTDESC

Definition: **ARRAY_SORT(**Array** $list, **$(item)** comparator)**

This function is identical to ARRAY_SORT, except it will return the results in the reverse order.