Skip to content

isSubset - Check if one array is contained within another array

Returns true if array1 is a subset of 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, isSubset supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

isSubset(array1: array<T>, array2: array<T>): bool
array1: array<T>.isSubset(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:

{
    "all_jobs": ["Chris", "John", "Adam", "Ariel", "Zev"],
    "started_jobs": ["Chris", "John"]
}

If we wish to check that started_jobs is a subset of all_jobs, we can do the following:

create is_subset from isSubset(started_jobs, all_jobs)
create is_subset from started_jobs.isSubset(all_jobs)

This results in the following document:

{
    "all_jobs": ["Chris", "John", "Adam", "Ariel", "Zev"],
    "started_jobs": ["Chris", "John"],
    "is_subset": true
}