source: node_modules/es-toolkit/dist/array/unionWith.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.3 KB
Line 
1/**
2 * Creates an array of unique values from two given arrays based on a custom equality function.
3 *
4 * This function takes two arrays and a custom equality function, merges the arrays, and returns
5 * a new array containing only the unique values as determined by the custom equality function.
6 *
7 * @template T - The type of elements in the array.
8 * @param {T[]} arr1 - The first array to merge and filter for unique values.
9 * @param {T[]} arr2 - The second array to merge and filter for unique values.
10 * @param {(item1: T, item2: T) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
11 * It takes two arguments and returns `true` if the elements are considered equal, and `false` otherwise.
12 * @returns {T[]} A new array of unique values based on the custom equality function.
13 *
14 * @example
15 * const array1 = [{ id: 1 }, { id: 2 }];
16 * const array2 = [{ id: 2 }, { id: 3 }];
17 * const areItemsEqual = (a, b) => a.id === b.id;
18 * const result = unionWith(array1, array2, areItemsEqual);
19 * // result will be [{ id: 1 }, { id: 2 }, { id: 3 }] since { id: 2 } is considered equal in both arrays
20 */
21declare function unionWith<T>(arr1: readonly T[], arr2: readonly T[], areItemsEqual: (item1: T, item2: T) => boolean): T[];
22
23export { unionWith };
Note: See TracBrowser for help on using the repository browser.