How to find Duplicate Elements in Array? I have array of phone numbers so in the phone numbers i should start searching from the right side to the left side and find similar
Based on Rob's answer, an array extension to just finds duplicates is:
extension Array where Element: Hashable {
func duplicates() -> Array {
let groups = Dictionary(grouping: self, by: {$0})
let duplicateGroups = groups.filter {$1.count > 1}
let duplicates = Array(duplicateGroups.keys)
return duplicates
}
}