source: node_modules/es-toolkit/dist/compat/array/uniqWith.d.mts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.2 KB
Line 
1type Comparator<T> = (a: T, b: T) => boolean;
2/**
3 * This method is like `uniq`, except that it accepts a `comparator` which is used to determine the equality of elements.
4 *
5 * It creates a duplicate-free version of an array, in which only the first occurrence of each element is kept.
6 * If a `comparator` is provided, it will be invoked with two arguments: `(arrVal, othVal)` to compare elements.
7 * If no comparator is provided, shallow equality is used.
8 *
9 * The order of result values is determined by the order they appear in the input array.
10 *
11 * @template T - The type of elements in the array.
12 * @param {ArrayLike<T> | null | undefined} arr - The array to process.
13 * @param {Comparator<T>} [comparator] - Optional function to compare elements for equality.
14 * @returns {T[]} A new array with only unique values based on the comparator.
15 *
16 * @example
17 * const array = [1, 2, 2, 3];
18 * const result = uniqWith(array);
19 * // result will be [1, 2, 3]
20 *
21 * const array = [1, 2, 3];
22 * const result = uniqWith(array, (a, b) => a % 2 === b % 2)
23 * // result will be [1, 2]
24 */
25declare function uniqWith<T>(arr: ArrayLike<T> | null | undefined, comparator?: Comparator<T>): T[];
26
27export { uniqWith };
Note: See TracBrowser for help on using the repository browser.