-
Notifications
You must be signed in to change notification settings - Fork 7
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
Stage 1 Entrance Criteria #2
Comments
IMHO “prose outlining the problem or need” could be clarified: what are some example use cases where deduplication in this manner is needed? The current README simply says this is “common” without backing up that claim. I’m particularly interested to hear use cases for |
I don’t quite understand, can you explain? @mathiasbynens I add Typical cases in ReadMe. Sometimes, we may need 2 or more key-value pairs as a hash to deduplicate an array. |
@TechQuery I also think the problem statement should be made more clear. I think from the example cases that you're interested in using an object's arbitrary property value as the unique key, instead of the object's identity? |
@jridgewell Sometimes, |
This comment has been minimized.
This comment has been minimized.
Let's please not discuss My point is that we already have Imagine you have model instances from a database. But, there are duplicate entries in our array (for whatever reason):
const models = [
new Model({ id: 1, value: 'foo' }),
new Model({ id: 2, value: 'bar' }),
new Model({ id: 1, value: 'foo' }),
];
You might be tempted to use `[...new Set(models)]` to create an array containing only unique instances. But if we try this, we'll see that we still have two `foo` models.
const notReallyUnique = [...new Set(models)];
assert.equals(notReallyUnique.length, 3); // We still have 3 models!
This is because `Set` uses object identity, and each `Model` instance has it's own unique identity. What we really want to do is use the `id` property to compare values, not object identity.
const unique = models.unique(model => model.id);
assert.equals(unique.length, 2); // We dropped the last `foo` model! |
we have reached stage 1 so I'm closing this! 🎉 |
https://tc39.es/process-document/
The text was updated successfully, but these errors were encountered: