intersect
Order comes from the first array, and the result is deduplicated: a value repeated there appears once. Values are compared with SameValueZero, the rule a Set uses, so NaN intersects with NaN — which a comparison by === never does — and -0 matches 0.
The arrays after the first each become a set once, and the first is then walked a single time. The cost is linear in the total input rather than the nested scan a hand-written version usually ends up being. The inputs are not modified.
Called with a single array, intersect returns its unique values; called with none, it returns [].
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The arrays to intersect. Left untouched. |
Returns
T[] — a new array of the shared values, in the order of the first array, without duplicates.
Throws
Exception | Condition |
|---|---|
| Any argument is not an array. |
Examples
Values shared by every array
Finding the rows two sheets have in common
Deduplication and edge cases
See also
Source
This documentation was generated with AI (Claude) from the library's source code.