UNPKG

@snap/camera-kit

Version:
29 lines 1.26 kB
/** * Creates an array of unique values, in order, from all given arrays using a specified iteratee. * If multiple elements have the same key generated by the iteratee, the last occurrence is kept. * * @param {((item: T) => unknown) | keyof T} iteratee - The iteratee invoked per element. * @param {...T[][]} arrays - The arrays to inspect and unite. * @returns {T[]} - Returns the new array of combined elements, preserving the order of last occurrences. * @example * // Using a property name as iteratee * const result = unionBy( * 'id', * [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }], * [{ id: 1, name: 'Sally' }, { id: 3, name: 'Doe' }] * ); * console.log(result); * // Output: [{ id: 1, name: 'Sally' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' }] * * @example * // Using a function as iteratee * const result = unionBy( * item => item.id, * [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }], * [{ id: 1, name: 'Sally' }, { id: 3, name: 'Doe' }] * ); * console.log(result); * // Output: [{ id: 1, name: 'Sally' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' }] */ export declare function unionBy<T>(iteratee: ((item: T) => unknown) | keyof T, ...arrays: T[][]): T[]; //# sourceMappingURL=unionBy.d.ts.map