Skip to content

setEqualsTo - Check equality of two sets

setEqualsTo returns true if array1 has the same elements as array2.

Note

When comparing array1 and array2, duplicates will be discarded. This means two arrays of differing lengths but the same unique elements will be considered equal.

Syntax

Like many functions in DataPrime, setEqualsTo supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

setEqualsTo(array1: array<T>, array2: array<T>): bool
array1: array<T>.setEqualsTo(array2: array<T>): bool

Arguments

NameTypeRequiredDescription
array1array of type TtrueT must be either string, bool, number, interval, timestamp, regexp or enum
array2array of type TtrueT must be either string, bool, number, interval, timestamp, regexp or enum

Example - Basic usage

Consider the following document:

{
    "array_1": ["val1", "val1", "val2", "val2", "val3"],
    "array_2": ["val1", "val2", "val3", "val3", "val3"]
}

We can see that while these two arrays have different counts of the values, they both possess the same unique values. We can check this, using setEqualsTo:

create arrays_equal from setEqualsTo(array_1, array_2)
create arrays_equal from array_1.setEqualsTo(array_2)

This results in the following document:

{
    "array_1": ["val1", "val1", "val2", "val2", "val3"],
    "array_2": ["val1", "val2", "val3", "val3", "val3"],
    "arrays_equal": true
}