I might have an array that looks like the following:
[1, 4, 2, 2, 6, 24, 15, 2, 60, 15, 6]
Or, reall
Swift 4
public extension Array where Element: Hashable {
func uniqued() -> [Element] {
var seen = Set()
return filter{ seen.insert($0).inserted }
}
}
every attempt to insert
will also return a tuple: (inserted: Bool, memberAfterInsert: Set.Element)
. See documentation.
Using the returned value helps us to avoid looping or doing any other operation.