Created
October 25, 2022 09:07
-
-
Save JanGorman/dd1ad2373db5c15e0363cbd39ee4fc72 to your computer and use it in GitHub Desktop.
Deduplicate array while keeping sort order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func deduplicated() -> [Element] { | |
var set = Set<String>() | |
// Whatever property or the entire thing if Hashable | |
return filter { set.insert($0.name).inserted } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment