Function: intersect()
intersect<
ElementType>(first:IterableResolvable<ElementType>,second:IterableResolvable<ElementType>):IterableIterator<ElementType>
Defined in: projects/utilities/packages/iterator-utilities/src/lib/intersect.ts:26
Creates an iterable with the elements that are in both input iterables.
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 include in the result. |
Returns
IterableIterator<ElementType>
Example
import { intersect } from '@sapphire/iterator-utilities';
const iterable = intersect([1, 2, 3, 4, 5], [3, 4, 5, 6, 7]);
console.log([...iterable]);
// Output: [3, 4, 5]
Remarks
This function consumes the entire second iterator to build the set of elements to intersect with first.
Seealso
difference for the opposite behavior.