Tusker/Tusker/Extensions/Array+Uniques.swift

24 lines
493 B
Swift

//
// Array+Uniques.swift
// Tusker
//
// Created by Shadowfacts on 1/6/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Foundation
extension Array where Element: Hashable {
func uniques() -> [Element] {
var buffer = [Element]()
var added = Set<Element>()
for elem in self {
if !added.contains(elem) {
buffer.append(elem)
added.insert(elem)
}
}
return buffer
}
}