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

Maps comparison : same key/value can be used multiple times #58

Closed
g-traub opened this issue Dec 3, 2021 · 4 comments · Fixed by #59
Closed

Maps comparison : same key/value can be used multiple times #58

g-traub opened this issue Dec 3, 2021 · 4 comments · Fixed by #59
Assignees
Labels

Comments

@g-traub
Copy link
Collaborator

g-traub commented Dec 3, 2021

The first value in mapB in the example above is used twice, since the keys are equal.

const mapA = new Map([[{b: 'c'}, 2],[{b: 'c'}, 2]])
const mapB = new Map([[{b: 'c'}, 2], ['foo', 'different']])

deepEqual(mapA, mapB)) // true

Example here : https://runkit.com/g-traub/map-keys-comparison

Using sameValueZero comparison would fix this, but maybe change the current behaviour too much ?
With deep comparison, we would need to make sure the same key/value pair can't be used multiple times.

@planttheidea
Copy link
Owner

This is definitely an issue. Investigating now.

@planttheidea
Copy link
Owner

The issue actually appears to be because the value from mapA always find a match in mapB (the first value). I have a setup that uses a local cache to avoid matching previously-matched values, should have a change up shortly.

@planttheidea
Copy link
Owner

Also, same issue exists on Set. Eesh!

@planttheidea
Copy link
Owner

FYI I've added you as a collaborator on the project so that you can review the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants