source: node_modules/es-toolkit/dist/array/differenceWith.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.7 KB
Line 
1/**
2 * Computes the difference between two arrays based on a custom equality function.
3 *
4 * This function takes two arrays and a custom comparison function. It returns a new array containing
5 * the elements that are present in the first array but not in the second array. The comparison to determine
6 * if elements are equal is made using the provided custom function.
7 *
8 * @template T, U
9 * @param {T[]} firstArr - The array from which to get the difference.
10 * @param {U[]} secondArr - The array containing elements to exclude from the first array.
11 * @param {(x: T, y: U) => boolean} areItemsEqual - A function to determine if two items are equal.
12 * @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array
13 * according to the custom equality function.
14 *
15 * @example
16 * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
17 * const array2 = [{ id: 2 }, { id: 4 }];
18 * const areItemsEqual = (a, b) => a.id === b.id;
19 * const result = differenceWith(array1, array2, areItemsEqual);
20 * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
21 *
22 * @example
23 * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
24 * const array2 = [2, 4];
25 * const areItemsEqual = (a, b) => a.id === b;
26 * const result = differenceWith(array1, array2, areItemsEqual);
27 * // result will be [{ id: 1 }, { id: 3 }] since the element with id 2 is considered equal to the second array's element and is excluded from the result.
28 */
29declare function differenceWith<T, U>(firstArr: readonly T[], secondArr: readonly U[], areItemsEqual: (x: T, y: U) => boolean): T[];
30
31export { differenceWith };
Note: See TracBrowser for help on using the repository browser.