predictype

predictype v0.8.1


predictype / arrays / arrayComparison

Function: arrayComparison()

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

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

Compares two arrays using a variety of comparison operations.

Type Parameters

T

T

Type of the array elements.

Parameters

source

T[]

The source array to compare.

oper

ArrayComparisonOper

The comparison operation to perform (EQUALS, NOT_EQUALS, SAME_MEMBERS, SET_EQUALS, SET_NOT_EQUALS).

target

T[]

The target array to compare against the source.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

arrayComparison([1, 2, 3], 'equals', [1, 2, 3]); // true
arrayComparison([1, 2, 3], 'equals', [3, 2, 1]); // false
arrayComparison([1, 2, 3], 'not_equals', [1, 2, 4]); // true
arrayComparison([1, 2, 2], 'same_members', [2, 1, 2]); // true
arrayComparison([1, 2, 2], 'same_members', [2, 1]); // false
arrayComparison([1, 2, 2], 'set_equals', [2, 1]); // true
arrayComparison([1, 2, 2], 'set_equals', [2, 1, 3]); // false
arrayComparison([1, 2, 2], 'set_not_equals', [2, 1, 3]); // true
arrayComparison([1, 2, 2], 'set_not_equals', [2, 1]); // false

Remarks

Supported operators: