diff --git a/docs/ko/reference/array/uniqBy.md b/docs/ko/reference/array/uniqBy.md index d24188fe..eb22e283 100644 --- a/docs/ko/reference/array/uniqBy.md +++ b/docs/ko/reference/array/uniqBy.md @@ -23,3 +23,13 @@ function uniqBy(arr: T[], mapper: (item: T) => U): T[]; uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor); // [1.2, 2.1, 3.2, 5.7, 7.19] ``` + +```typescript +const array = [ + { category: 'fruit', name: 'apple' }, + { category: 'fruit', name: 'banana' }, + { category: 'vegetable', name: 'carrot' }, +]; +uniqBy(array, item => item.category).length +// 2 +``` \ No newline at end of file diff --git a/docs/reference/array/uniqBy.md b/docs/reference/array/uniqBy.md index 25fdf519..0ee36e9c 100644 --- a/docs/reference/array/uniqBy.md +++ b/docs/reference/array/uniqBy.md @@ -23,3 +23,14 @@ function uniqBy(arr: T[], mapper: (item: T) => U): T[]; uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor); // [1.2, 2.1, 3.2, 5.7, 7.19] ``` + +```typescript +const array = [ + { category: 'fruit', name: 'apple' }, + { category: 'fruit', name: 'banana' }, + { category: 'vegetable', name: 'carrot' }, +]; +uniqBy(array, item => item.category).length +// 2 +``` + diff --git a/docs/zh_hans/reference/array/uniqBy.md b/docs/zh_hans/reference/array/uniqBy.md index f1dbeaa2..241c4cdb 100644 --- a/docs/zh_hans/reference/array/uniqBy.md +++ b/docs/zh_hans/reference/array/uniqBy.md @@ -23,3 +23,13 @@ function uniqBy(arr: T[], mapper: (item: T) => U): T[]; 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] ``` + +```typescript +const array = [ + { category: 'fruit', name: 'apple' }, + { category: 'fruit', name: 'banana' }, + { category: 'vegetable', name: 'carrot' }, +]; +uniqBy(array, item => item.category).length +// 2 +``` diff --git a/src/array/uniqBy.ts b/src/array/uniqBy.ts index ab700ddf..5891d9e4 100644 --- a/src/array/uniqBy.ts +++ b/src/array/uniqBy.ts @@ -13,6 +13,16 @@ * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor); * // [1.2, 2.1, 3.2, 5.7, 7.19] * ``` + * + * @example + * const array = [ + * { category: 'fruit', name: 'apple' }, + * { category: 'fruit', name: 'banana' }, + * { category: 'vegetable', name: 'carrot' }, + * ]; + * uniqBy(array, item => item.category).length + * // 2 + * ``` */ export function uniqBy(arr: readonly T[], mapper: (item: T) => U): T[] { const map = new Map();