Skip to content

Instantly share code, notes, and snippets.

@karambirov
Created February 2, 2023 07:31
Show Gist options
  • Save karambirov/62e6ad18af17f3ad7a84eddf7133a38c to your computer and use it in GitHub Desktop.
Save karambirov/62e6ad18af17f3ad7a84eddf7133a38c to your computer and use it in GitHub Desktop.
Swift array extension for removing duplicates
public extension Array where Element: Hashable {
func withoutDuplicates() -> [Element] {
var seen = Set<Element>()
return filter { seen.insert($0).inserted }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment