Last active
September 10, 2018 07:58
-
-
Save jerrypm/7a6bb88c44f8381d5c2583387edd36f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ | |
// 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