predictype

predictype v0.8.1


predictype / predicates/arrays/arrayIndexComparison / arrayIndexComparison

Function: arrayIndexComparison()

arrayIndexComparison<T>(source, oper, index, target): boolean

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

Compares the value at a specific index in an array with a target value, using the specified operation.

Type Parameters

T

T

Type of the array elements.

Parameters

source

T[]

The source array.

oper

ArrayIndexComparisonOper

The comparison operation to perform (e.g. ‘at_index_equals’).

index

number

The index in the array to compare.

target

T

The value to compare against the value at the given index.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const arr = [10, 20, 30];
const idx1 = 1;
const idx2 = 2;
const val1 = 20;
const val2 = 25;

arrayIndexComparison(arr, 'at_index_equals', idx1, val1); // true
arrayIndexComparison(arr, 'at_index_greater_than', idx2, val2); // true

Remarks

Supported Operators: