Skip to content

Instantly share code, notes, and snippets.

@olgusirman
Created August 28, 2020 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olgusirman/732e299aab0e7ef03153866accfec21c to your computer and use it in GitHub Desktop.
Save olgusirman/732e299aab0e7ef03153866accfec21c to your computer and use it in GitHub Desktop.
Remove duplicates
public extension Array where Element: Hashable {
func removeDuplicates() -> [Element] {
var items = Set<Element>
return self.filter { items.insert($0).inserted }
}
}
// [1,2,5,5,2,4,3].removeDuplicates()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment