fix(intersectionBy): remove duplicates when mapper produces same values
Summary
Fixes: #956
Fixed a bug in intersectionBy where it returned duplicate elements from the first array when the mapper function produced identical values for multiple elements. Now correctly returns only the first occurrence of each mapped value.
For example, intersectionBy([2.1, 2.2], [2.3, 3.4], Math.floor) now correctly returns [2.1] instead of [2.1, 2.2].
Changes
- Modified
intersectionByto useuniqByon the first array before filtering - Added test case to verify duplicate removal behavior
Comment
- Would it be better to implement it myself rather than using the uniqBy function?
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| es-toolkit | Preview | Comment | Nov 24, 2025 3:00am |
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 99.97%. Comparing base (b6ffb6d) to head (2475241).
:warning: Report is 5 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #1528 +/- ##
=======================================
Coverage 99.97% 99.97%
=======================================
Files 474 474
Lines 4492 4493 +1
Branches 1313 1313
=======================================
+ Hits 4491 4492 +1
Misses 1 1
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
I'm sorry, but as we mentioned in the original comment, we would like to keep the original interface where we only accept two arrays and a mapper function. (We would not like to accept multiple arrays here since it violates our simplicity principle.)
However, we should fix a bug where calls like intersectionBy([2.1, 2.2], [2.3, 3.4], Math.floor) does not return [2.1]. (It is returning [2.1, 2.2].)
Sorry, I seem to have misunderstood your comment. I'll try to fix the bug you mentioned by submitting a PR.
@raon0211
I've fixed the bug and re-created the PR, sorry for the confusion.