Skip to content

Instantly share code, notes, and snippets.

@jerrypm
Last active September 10, 2018 07:58
Show Gist options
  • Save jerrypm/7a6bb88c44f8381d5c2583387edd36f0 to your computer and use it in GitHub Desktop.
Save jerrypm/7a6bb88c44f8381d5c2583387edd36f0 to your computer and use it in GitHub Desktop.
/
// ViewController.swift
// For Test Part 4
//
// Created by Jeri P.M on 10/09/18.
// Copyright © 2018 Jeri P.M . All rights reserved.
//
import UIKit
class SecsionLastVC: UIViewController {
var dataArray = ["a","a","a","b","b","c","c","e","f","c"]
var dataTab: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
for items in dataArray {
dataTab.append(items)
print(dataTab)
}
dataTab.removeDuplicates()
print(dataTab)
}
}
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