Skip to content

Instantly share code, notes, and snippets.

@JanGorman
Created October 25, 2022 09:07
Show Gist options
  • Save JanGorman/dd1ad2373db5c15e0363cbd39ee4fc72 to your computer and use it in GitHub Desktop.
Save JanGorman/dd1ad2373db5c15e0363cbd39ee4fc72 to your computer and use it in GitHub Desktop.
Deduplicate array while keeping sort order
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