2024-06-13 16:20:12 +03:00
|
|
|
# uniqBy
|
|
|
|
|
|
|
|
Returns a new array containing only the unique elements from the original array, based on the values returned by the `mapper` function.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```typescript
|
2024-06-19 11:29:50 +03:00
|
|
|
function uniqBy<T, U>(arr: T[], mapper: (item: T) => U): T[];
|
2024-06-13 16:20:12 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
|
|
|
- `arr` (`T[]`): The array to process.
|
|
|
|
- `mapper` (`(item: T) => U`): The function used to convert the array elements.
|
|
|
|
|
|
|
|
### Returns
|
|
|
|
|
|
|
|
(`T[]`): A new array containing only the unique elements from the original array, based on the values returned by the `mapper` function.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);
|
|
|
|
// [1.2, 2.1, 3.3, 5.7, 7.19]
|
|
|
|
```
|