predictype

predictype v0.8.1


predictype / predicates/arrays/arrayRelation / arrayRelation

Function: arrayRelation()

arrayRelation<T>(source, oper, target): boolean

Defined in: predicates/arrays/arrayRelation.ts:34

Checks if the source array is a subset, strict subset, superset, or strict superset of the target array, using the specified operation.

Type Parameters

T

T

Type of the array elements.

Parameters

source

T[]

The source array.

oper

ArrayRelationOper

The relation operation to perform (‘subset_of’, ‘superset_of’, ‘strict_subset_of’, ‘strict_superset_of’).

target

T[]

The target array to check against the source.

Returns

boolean

True if the relation check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Examples

arrayRelation([1, 2], 'subset_of', [1, 2, 3]); // true
arrayRelation([1, 2], 'subset_of', [1, 2]); // true (equality allowed)
arrayRelation([1, 2, 3], 'superset_of', [2, 3]); // true
arrayRelation([1, 2], 'superset_of', [1, 2]); // true (equality allowed)
arrayRelation([1, 2], 'strict_subset_of', [1, 2, 3]); // true
arrayRelation([1, 2], 'strict_subset_of', [1, 2]); // false (equality not allowed)
arrayRelation([1, 2, 3], 'strict_superset_of', [2, 3]); // true
arrayRelation([1, 2], 'strict_superset_of', [1, 2]); // false (equality not allowed)

Remarks

Supported Operators: