This method is an attempt at removing duplicates from arrays without the use of extensions.
func arrayWithDuplicatesRemoved<T: Equatable>(from array: [T]) -> [T] {
var results = [T]()
return array.compactMap { (element) -> T? in
if results.contains(element) {
return nil
} else {
results.append(element)
return element
}
}
}
let dirty = ["apple", "kiwi", "grapefruit", "kiwi", "kiwi", "strawberry", "watermelon", "apple", "banana"]
let clean = arrayWithDuplicatesRemoved(from: dirty)
print(clean) // ["apple", "kiwi", "grapes", "strawberry", "watermelon", "banana"]