docs(uniqBy): fix docs for uniqBy (#231)

* docs: fix uniqBy doc example

* test: add test case

---------

Co-authored-by: Sojin Park <raon0211@toss.im>
This commit is contained in:
novo 2024-07-18 21:12:44 +09:00 committed by GitHub
parent 553f136c94
commit 404d4a51a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 4 additions and 3 deletions

View File

@ -21,5 +21,5 @@ function uniqBy<T, U>(arr: T[], mapper: (item: T) => U): T[];
```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]
// [1.2, 2.1, 3.2, 5.7, 7.19]
```

View File

@ -21,5 +21,5 @@ function uniqBy<T, U>(arr: T[], mapper: (item: T) => U): T[];
```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]
// [1.2, 2.1, 3.2, 5.7, 7.19]
```

View File

@ -4,5 +4,6 @@ import { uniqBy } from './uniqBy';
describe('uniqBy', () => {
it('should work with a `mapper`', () => {
expect(uniqBy([2.1, 1.2, 2.3], Math.floor)).toEqual([2.1, 1.2]);
expect(uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor)).toEqual([1.2, 2.1, 3.2, 5.7, 7.19]);
});
});

View File

@ -11,7 +11,7 @@
* @example
* ```ts
* 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]
* // [1.2, 2.1, 3.2, 5.7, 7.19]
* ```
*/
export function uniqBy<T, U>(arr: readonly T[], mapper: (item: T) => U): T[] {