source: node_modules/es-toolkit/dist/compat/array/differenceWith.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: 4.8 KB
Line 
1/**
2 * Computes the difference between the primary array and another array using a comparator function.
3 *
4 * @template T1, T2
5 * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
6 * @param {ArrayLike<T2>} values - The array containing elements to compare with the primary array.
7 * @param {(a: T1, b: T2) => boolean} comparator - A function to determine if two elements are considered equal.
8 * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values` based on the comparator.
9 *
10 * @example
11 * const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
12 * const values = [{ id: 2 }];
13 * const comparator = (a, b) => a.id === b.id;
14 *
15 * const result = differenceWith(array, values, comparator);
16 * // result will be [{ id: 1 }, { id: 3 }]
17 */
18declare function differenceWith<T1, T2>(array: ArrayLike<T1> | null | undefined, values: ArrayLike<T2>, comparator: (a: T1, b: T2) => boolean): T1[];
19/**
20 * Computes the difference between the primary array and two arrays using a comparator function.
21 *
22 * @template T1, T2, T3
23 * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
24 * @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
25 * @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
26 * @param {(a: T1, b: T2 | T3) => boolean} comparator - A function to determine if two elements are considered equal.
27 * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements in `values1` or `values2` based on the comparator.
28 *
29 * @example
30 * const array = [{ id: 1 }, { id: 2 }, { id: 3 }];
31 * const values1 = [{ id: 2 }];
32 * const values2 = [{ id: 3 }];
33 * const comparator = (a, b) => a.id === b.id;
34 *
35 * const result = differenceWith(array, values1, values2, comparator);
36 * // result will be [{ id: 1 }]
37 */
38declare function differenceWith<T1, T2, T3>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, comparator: (a: T1, b: T2 | T3) => boolean): T1[];
39/**
40 * Computes the difference between the primary array and multiple arrays using a comparator function.
41 *
42 * @template T1, T2, T3, T4
43 * @param {ArrayLike<T1> | null | undefined} array - The primary array to compare elements against.
44 * @param {ArrayLike<T2>} values1 - The first array containing elements to compare with the primary array.
45 * @param {ArrayLike<T3>} values2 - The second array containing elements to compare with the primary array.
46 * @param {...Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>} values - Additional arrays and an optional comparator function to determine if two elements are considered equal.
47 * @returns {T1[]} A new array containing the elements from the primary array that do not match any elements
48 * in `values1`, `values2`, or subsequent arrays. If a comparator function is provided, it will be used to compare elements;
49 * otherwise, [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero) algorithm will be used.
50 *
51 * @example
52 * // Example with comparator function
53 * const array = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
54 * const values1 = [{ id: 2 }];
55 * const values2 = [{ id: 3 }];
56 * const values3 = [{ id: 4 }];
57 * const comparator = (a, b) => a.id === b.id;
58 *
59 * const result = differenceWith(array, values1, values2, values3, comparator);
60 * // result will be [{ id: 1 }]
61 *
62 * @example
63 * // Example without comparator function (behaves like `difference`)
64 * const array = [1, 2, 3, 4];
65 * const values1 = [2];
66 * const values2 = [3];
67 * const values3 = [4];
68 *
69 * const result = differenceWith(array, values1, values2, values3);
70 * // result will be [1]
71 */
72declare function differenceWith<T1, T2, T3, T4>(array: ArrayLike<T1> | null | undefined, values1: ArrayLike<T2>, values2: ArrayLike<T3>, ...values: Array<ArrayLike<T4> | ((a: T1, b: T2 | T3 | T4) => boolean)>): T1[];
73/**
74 * Computes the difference between the primary array and one or more arrays without using a comparator function.
75 *
76 * @template T
77 * @param {ArrayLike<T> | null | undefined} array - The primary array to compare elements against.
78 * @param {...Array<ArrayLike<T>>} values - One or more arrays containing elements to compare with the primary array.
79 * @returns {T[]} A new array containing the elements from the primary array that do not match any elements in the provided arrays.
80 *
81 * @example
82 * const array = [1, 2, 3];
83 * const values1 = [2];
84 * const values2 = [3];
85 *
86 * const result = differenceWith(array, values1, values2);
87 * // result will be [1]
88 */
89declare function differenceWith<T>(array: ArrayLike<T> | null | undefined, ...values: Array<ArrayLike<T>>): T[];
90
91export { differenceWith };
Note: See TracBrowser for help on using the repository browser.