| 1 | /**
|
|---|
| 2 | * Returns a new array containing only the unique elements from the original array,
|
|---|
| 3 | * based on the values returned by the mapper function.
|
|---|
| 4 | *
|
|---|
| 5 | * When duplicates are found, the first occurrence is kept and the rest are discarded.
|
|---|
| 6 | *
|
|---|
| 7 | * @template T - The type of elements in the array.
|
|---|
| 8 | * @template U - The type of mapped elements.
|
|---|
| 9 | * @param {T[]} arr - The array to process.
|
|---|
| 10 | * @param {(item: T) => U} mapper - The function used to convert the array elements.
|
|---|
| 11 | * @returns {T[]} A new array containing only the unique elements from the original array, based on the values returned by the mapper function.
|
|---|
| 12 | *
|
|---|
| 13 | * @example
|
|---|
| 14 | * ```ts
|
|---|
| 15 | * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);
|
|---|
| 16 | * // [1.2, 2.1, 3.2, 5.7, 7.19]
|
|---|
| 17 | * ```
|
|---|
| 18 | *
|
|---|
| 19 | * @example
|
|---|
| 20 | * const array = [
|
|---|
| 21 | * { category: 'fruit', name: 'apple' },
|
|---|
| 22 | * { category: 'fruit', name: 'banana' },
|
|---|
| 23 | * { category: 'vegetable', name: 'carrot' },
|
|---|
| 24 | * ];
|
|---|
| 25 | * uniqBy(array, item => item.category).length
|
|---|
| 26 | * // 2
|
|---|
| 27 | * ```
|
|---|
| 28 | */
|
|---|
| 29 | declare function uniqBy<T, U>(arr: readonly T[], mapper: (item: T, index: number, array: readonly T[]) => U): T[];
|
|---|
| 30 |
|
|---|
| 31 | export { uniqBy };
|
|---|