UNPKG

typedash

Version:

modern, type-safe collection of utility functions

28 lines (26 loc) 1.06 kB
/** * Gets the intersection 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 intersection between the two arrays. * @example * ```ts * intersection([1, 2, 3], [2, 3, 4]) // [2, 3] * ``` */ declare function intersection<const T, const S extends T>(array1: readonly T[], array2: readonly S[], comparator?: Comparator<T, S>): S[]; /** * Gets the intersection 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 intersection between the two arrays. * @example * ```ts * intersection([1, 2, 3], [2, 3, 4]) // [2, 3] * ``` */ declare function intersection<T, S extends T>(array1: readonly T[], array2: readonly S[], comparator?: Comparator<T, S>): S[]; type Comparator<T, S extends T> = ((a: T, b: S) => a is S) | ((a: T, b: S) => boolean); export { intersection };