Skip to content

Instantly share code, notes, and snippets.

@pvn
Last active September 15, 2018 00:34
Show Gist options
  • Save pvn/5193e8c234018acd78a9782d18d47798 to your computer and use it in GitHub Desktop.
Save pvn/5193e8c234018acd78a9782d18d47798 to your computer and use it in GitHub Desktop.
Swift: Array Extension
/* Compare two array has the same value */
// firstArray = ['A', 'B', 'C', 'A']
// secondArray = ['A', 'B', 'C', 'A']
// firstArray.isDuplicateOf(secondArray)
extension Array where Element: Comparable {
func isDuplicateOf(as other: [Element]) -> Bool {
return self.count == other.count && self.sorted() == other.sorted()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment