VDL Plugin SDK

uniqWith

Import from @varavel/vdl-plugin-sdk/utils/arrays.

function uniqWith<T>(arr, areItemsEqual): T[];

Returns a new array containing only the unique elements from the original array, based on the values returned by the comparator function.

Type Parameters

Type ParameterDescription
TThe type of elements in the array.

Parameters

ParameterTypeDescription
arrreadonly T[]The array to process.
areItemsEqual(item1, item2) => booleanThe function used to compare the array elements.

Returns

T[]

A new array containing only the unique elements from the original array, based on the values returned by the comparator function.

Example

uniqWith([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], (a, b) => Math.abs(a - b) < 1);
// [1.2, 3.2, 5.7, 7.19]