Remove the duplicate values in an array iOS swift
Problem:
I had an array that contains duplicate values.How do i remove the duplicate values?
Solution:
extension Array where Element: Equatable {
func removingDuplicates() -> Array {
return reduce(into: []) { result, element in
if !result.contains(element) {
result.append(element)
}
}
}
}
Comments
Post a Comment