UNPKG

typedash

Version:

modern, type-safe collection of utility functions

31 lines (30 loc) 1.46 kB
import { IsLiteral } from "type-fest"; //#region src/functions/difference/difference.d.ts /** * Gets the difference between two arrays. * @param array1 The first array. * @param array2 The second array. * @param comparator A function that determines whether two items are equal. * @returns An array with the difference between the two arrays - items that are in the first array but not in the second. * @example * ```ts * difference([1, 2, 3], [2, 3, 4]) // [2, 3] * ``` */ declare function difference<const T, const S extends T>(array1: readonly T[], array2: readonly S[], comparator?: Comparator<T, S>): Array<IsLiteral<T> | IsLiteral<S> extends true ? Exclude<T, S> : T>; /** * Gets the difference between two arrays. * @param array1 The first array. * @param array2 The second array. * @param comparator A function that determines whether two items are equal. * @returns An array with the difference between the two arrays - items that are in the first array but not in the second. * @example * ```ts * difference([1, 2, 3], [2, 3, 4]) // [2, 3] * ``` */ declare function difference<T, S extends T>(array1: readonly T[], array2: readonly S[], comparator?: Comparator<T, S>): Array<IsLiteral<T> | IsLiteral<S> extends true ? Exclude<T, S> : T>; type Comparator<T, S extends T> = ((a: T, b: S) => a is Exclude<T, S>) | ((a: T, b: S) => boolean); //#endregion export { difference as t }; //# sourceMappingURL=difference-Byn-ybm4.d.cts.map