Created
September 11, 2018 05:52
-
-
Save geek1706/3e7719334579f8b5b5ba27d3db00fef0 to your computer and use it in GitHub Desktop.
Remove duplicate array
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
public extension Array where Element: Hashable { | |
func sync(with array: Array) -> Array { | |
print("before:\(self)") | |
var seen = Set<Element>() | |
let result = filter{ seen.insert($0).inserted } | |
print("after: \(result)") | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment