Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About intersection #6

Open
dgilperez opened this issue Mar 28, 2021 · 2 comments
Open

About intersection #6

dgilperez opened this issue Mar 28, 2021 · 2 comments

Comments

@dgilperez
Copy link
Collaborator

dgilperez commented Mar 28, 2021

I was playing with intersection to see if that would allow us to find the elements in common in two arrays, but I am confused to see it does the opposite: it merges the two collections by applying a union function ... so my questions / comments:

  • I think current implementation is actually an union or join, not an intersection, in Venn's terms. If I'm not mistaken, I'd suggest a rename ... although that'd be a breaking change. Moreover when I'd suggest to add a different intersection function ...
  • Can intersection or other function in m be use to obtain that the elements in common in two lists? Would you accept a PR for that? What name would you give it?
@dgilperez
Copy link
Collaborator Author

About the latter, I think this will to the job arrA.filter(x => arrB.includes(x)). Happy to contribute this in any case.

@dgilperez
Copy link
Collaborator Author

This will also work on objects, for what I see:

const _intersection = (aList, bList) => {
  if (bList.length === 0) {
    return []
  }

  return filter(source => any(isDeepEqual(source), bList), aList)
}

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

No branches or pull requests

1 participant