mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-30 18:23:22 +03:00
854 B
854 B
uniqWith
Returns a new array containing only the unique elements from the original array, based on the values returned by the comparator function.
Signature
function uniqWith<T>(arr: T[], areItemsEqual: (item1: T, item2: T) => boolean): T[];
Parameters
arr
(T[]
): The array to process.areItemsEqual
((x: T, y: T) => boolean
): A custom function to determine if two elements are equal. This function takes two arguments, one from each array, and returnstrue
if the elements are considered equal, andfalse
otherwise.
Returns
(T[]
): A new array containing only the unique elements from the original array, based on the values returned by the comparator function.
Examples
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]