Skip to content

Conversation

@wo-o29
Copy link
Contributor

@wo-o29 wo-o29 commented Nov 21, 2025

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 intersectionBy to use uniqBy on 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?

Copilot AI review requested due to automatic review settings November 21, 2025 09:17
@vercel
Copy link

vercel bot commented Nov 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
es-toolkit Ready Ready Preview Comment Nov 24, 2025 3:00am

Copilot finished reviewing on behalf of wo-o29 November 21, 2025 09:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the intersectionBy function to support finding the intersection of three or more arrays using a mapping function, while maintaining backward compatibility with the existing two-array signature. The enhancement allows developers to find common elements across multiple arrays based on a transformed value, which is useful for complex data filtering scenarios.

Key Changes:

  • Modified the function signature to accept a variable number of arrays using rest parameters, with the mapper function as the last argument
  • Updated implementation to iteratively filter elements across all provided arrays
  • Added comprehensive test coverage for 3+ array scenarios and edge cases

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/array/intersectionBy.ts Enhanced function to support multiple arrays with iterative filtering logic and updated JSDoc documentation
src/array/intersectionBy.spec.ts Added test cases for 3+ arrays, 4+ arrays, and empty intersection scenarios
docs/reference/array/intersectionBy.md Updated English documentation with multi-array examples and parameter descriptions
docs/ko/reference/array/intersectionBy.md Updated Korean documentation with multi-array examples and parameter descriptions
docs/ja/reference/array/intersectionBy.md Updated Japanese documentation with multi-array examples and parameter descriptions
docs/zh_hans/reference/array/intersectionBy.md Updated Chinese documentation with multi-array examples and parameter descriptions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter
Copy link

codecov-commenter commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (b6ffb6d) to head (2475241).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           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           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@raon0211
Copy link
Collaborator

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].)

@wo-o29
Copy link
Contributor Author

wo-o29 commented Nov 24, 2025

Sorry, I seem to have misunderstood your comment. I'll try to fix the bug you mentioned by submitting a PR.

@wo-o29 wo-o29 changed the title fix(intersectionBy): support three or more arrays fix(intersectionBy): remove duplicates when mapper produces same values Nov 24, 2025
@wo-o29
Copy link
Contributor Author

wo-o29 commented Nov 24, 2025

@raon0211

I've fixed the bug and re-created the PR, sorry for the confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intersectionBy difference with lodash

3 participants