-
Notifications
You must be signed in to change notification settings - Fork 441
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
A Method for Removing All Elements in One Array that Exist in Another #166
Comments
That example could be written quite easily with let excludedAnimals = ["Bulldog", "Labrador"]
return animals.filter({ !excludedAnimals.contains($0) }) // ["Cow"] The algorithmic complexity of this, however, is O(n×m) where n is the number of elements in the first array and m is the number of elements in the exclusion array. If converting the elements into a let excludedAnimals = Set(arrayLiteral: "Bulldog", "Labrador")
return animals.filter({ !excludedAnimals.contains($0) }) // ["Cow"] I wouldn’t expect there’d be a ton of value in a function like this specifically, unless it automatically managed the conditional conversion to a |
It could be written that way, just as most things could be written via a |
Conceptually this would be just a generalization of One suggestion, is that this issue tracking would not reach to many people because only few watch this repo, so maybe if we want an input from more members of the community an idea would be have a forums thread for it under algorithms topic, if you think is worth it. But it is only a suggestion :) |
Quick style note:
This usually reads better when spelled: let excludedAnimals: Set = ["Bulldog", "Labrador"] |
@lorentey Good point—I had forgotten about that. Thanks! |
This is a "subtract" operation, e.g.:
We can see that this is an operation Swift developers are already trying to do from SO questions (1, 2), and it exists in other languages like Ruby.
This is a proposal to get consensus on it. And if people like it, I'd be happy to implement it.
The text was updated successfully, but these errors were encountered: