Function: unique()
unique<
ElementType>(iterable:IterableResolvable<ElementType>):IterableIterator<ElementType>
Defined in: projects/utilities/packages/iterator-utilities/src/lib/unique.ts:19
Creates an iterable with the unique elements of the input iterable. Under the hood, it calls union with the iterable itself.
Type Parameters
| Type Parameter |
|---|
ElementType |
Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | IterableResolvable<ElementType> | An iterator to remove duplicates from. |
Returns
IterableIterator<ElementType>
An iterator that yields the values of the provided iterator with duplicates removed.
Example
import { unique } from '@sapphire/iterator-utilities';
const iterable = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5];
console.log([...unique(iterable)]);
// Output: [1, 2, 3, 4, 5]