source: node_modules/es-toolkit/dist/array/intersectionWith.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: 2.0 KB
Line 
1/**
2 * Returns the intersection of two arrays based on a custom equality function.
3 *
4 * This function takes two arrays and a custom equality function. It returns a new array containing
5 * the elements from the first array that have matching elements in the second array, as determined
6 * by the custom equality function. It effectively filters out any elements from the first array that
7 * do not have corresponding matches in the second array according to the equality function.
8 *
9 * @template T - The type of elements in the first array.
10 * @template U - The type of elements in the second array.
11 * @param {T[]} firstArr - The first array to compare.
12 * @param {U[]} secondArr - The second array to compare.
13 * @param {(x: T, y: U) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
14 * This function takes two arguments, one from each array, and returns `true` if the elements are considered equal, and `false` otherwise.
15 * @returns {T[]} A new array containing the elements from the first array that have corresponding matches in the second array according to the custom equality function.
16 *
17 * @example
18 * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
19 * const array2 = [{ id: 2 }, { id: 4 }];
20 * const areItemsEqual = (a, b) => a.id === b.id;
21 * const result = intersectionWith(array1, array2, areItemsEqual);
22 * // result will be [{ id: 2 }] since this element has a matching id in both arrays.
23 *
24 * @example
25 * const array1 = [
26 * { id: 1, name: 'jane' },
27 * { id: 2, name: 'amy' },
28 * { id: 3, name: 'michael' },
29 * ];
30 * const array2 = [2, 4];
31 * const areItemsEqual = (a, b) => a.id === b;
32 * const result = intersectionWith(array1, array2, areItemsEqual);
33 * // result will be [{ id: 2, name: 'amy' }] since this element has a matching id that is equal to seconds array's element.
34 */
35declare function intersectionWith<T, U>(firstArr: readonly T[], secondArr: readonly U[], areItemsEqual: (x: T, y: U) => boolean): T[];
36
37export { intersectionWith };
Note: See TracBrowser for help on using the repository browser.