Created
February 2, 2023 07:31
-
-
Save karambirov/62e6ad18af17f3ad7a84eddf7133a38c to your computer and use it in GitHub Desktop.
Swift array extension for removing duplicates
This file contains hidden or 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
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