Function: difference()
difference<
ElementType
>(first
:IterableResolvable
<ElementType
>,second
:IterableResolvable
<ElementType
>):IterableIterator
<ElementType
>
Creates an iterable with the elements of the first iterable that are not in the second iterable.
Type Parameters
Type Parameter |
---|
ElementType |
Parameters
Parameter | Type | Description |
---|---|---|
first | IterableResolvable <ElementType > | An iterator to return elements from. |
second | IterableResolvable <ElementType > | An iterator that contains elements to exclude from the result. |
Returns
IterableIterator
<ElementType
>
Example
import { difference } from '@sapphire/iterator-utilities';
const first = [1, 2, 3, 4, 5];
const second = [3, 4, 5, 6, 7];
console.log([...difference(first, second)]);
// Output: [1, 2]
Remarks
This function consumes the entire second
iterator to build the set of elements to exclude from first
.
Defined in
projects/utilities/packages/iterator-utilities/src/lib/difference.ts:25