📜  快速从数组中删除所有重复项 - Swift 代码示例

📅  最后修改于: 2022-03-11 15:01:01.329000             🧑  作者: Mango

代码示例1
extension Sequence where Element: Hashable {
    func uniqued() -> [Element] {
        var set = Set()
        return filter { set.insert($0).inserted }
    }
}

func foobar() {
    let myUniqueArray = [1,2,4,2,1].uniqued()  // => [1,2,4]
}