Skip to content

Instantly share code, notes, and snippets.

@wbbernardes
Last active August 15, 2019 13:12
Show Gist options
  • Save wbbernardes/2a4f4c0301ac5c872cfa2bfa001211e0 to your computer and use it in GitHub Desktop.
Save wbbernardes/2a4f4c0301ac5c872cfa2bfa001211e0 to your computer and use it in GitHub Desktop.
Remove duplicate elemente in array
//
// Array+RemoveDuplicate.swift
//
// Created by Wesley Brito on 12/08/19.
// Copyright © 2019 Wesley Brito. All rights reserved.
//
import Foundation
extension Array where Element: Hashable {
func removingDuplicates() -> [Element] {
var addedDict = [Element: Bool]()
return filter {
addedDict.updateValue(true, forKey: $0) == nil
}
}
mutating func removeDuplicates() {
self = self.removingDuplicates()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment