source: node_modules/es-toolkit/dist/array/unionBy.d.ts

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.1 KB
Line 
1/**
2 * Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality.
3 *
4 * @template T - The type of elements in the array.
5 * @template U - The type of mapped elements.
6 * @param {T[]} arr1 - The first array.
7 * @param {T[]} arr2 - The second array.
8 * @param {(item: T) => U} mapper - The function to map array elements to comparison values.
9 * @returns {T[]} A new array containing the union of unique elements from `arr1` and `arr2`, based on the values returned by the mapping function.
10 *
11 * @example
12 * // Custom mapping function for numbers (modulo comparison)
13 * const moduloMapper = (x) => x % 3;
14 * unionBy([1, 2, 3], [4, 5, 6], moduloMapper);
15 * // Returns [1, 2, 3]
16 *
17 * @example
18 * // Custom mapping function for objects with an 'id' property
19 * const idMapper = (obj) => obj.id;
20 * unionBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper);
21 * // Returns [{ id: 1 }, { id: 2 }, { id: 3 }]
22 */
23declare function unionBy<T, U>(arr1: readonly T[], arr2: readonly T[], mapper: (item: T) => U): T[];
24
25export { unionBy };
Note: See TracBrowser for help on using the repository browser.