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

just-intersect is mixing array and strings #572

Open
Nikaple opened this issue Jan 3, 2024 · 3 comments
Open

just-intersect is mixing array and strings #572

Nikaple opened this issue Jan 3, 2024 · 3 comments

Comments

@Nikaple
Copy link

Nikaple commented Jan 3, 2024

const intersect = require('just-intersect')

intersect([1, "2", 5, 6], [2, 3, 5, 6]); // ["2", 5, 6]

lodash.intersection gives [5, 6] on such cases.

@uncenter
Copy link

uncenter commented Jan 3, 2024

Looks like the issue is that the current implementation creates objects where the items of the arrays are the properties, which causes the behavior you explained since items are casted to strings (https://github.com/angus-c/just/blob/master/packages/array-intersect/index.mjs#L35); e.g. [2, 3, 5, 6] becomes { '2': true, '3': true, '5': true, '6': true }, so then checking if "2" is a property of that object results in that issue.

@Nikaple
Copy link
Author

Nikaple commented Jan 3, 2024

Yeah, there's some workaround and I'm using a set-based method which is O(n). Just curious if the library author is willing to fix this, as it's a breaking change.

@uncenter
Copy link

uncenter commented Jan 3, 2024

The author hasn't been active since last May unfortunately. I'm also eagerly awaiting their return ahah.

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

2 participants