Skip to content

Instantly share code, notes, and snippets.

@hechen
Created December 14, 2022 04:47
Show Gist options
  • Save hechen/c311adbf192a07b9ad6f3ddef948c610 to your computer and use it in GitHub Desktop.
Save hechen/c311adbf192a07b9ad6f3ddef948c610 to your computer and use it in GitHub Desktop.
/// Taken from here: https://stackoverflow.com/a/46354989/491239
public
extension Array where Element : Hashable {
static func removeDuplicates(_ elements: [Element]) -> [Element] {
var seen = Set<Element>() return elements.filter { seen.insert($0).inserted }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment