Skip to content

Instantly share code, notes, and snippets.

@Gujci
Created June 10, 2016 10:56
Show Gist options
  • Save Gujci/d497ca7f64b84407b870b15d0ba54bf3 to your computer and use it in GitHub Desktop.
Save Gujci/d497ca7f64b84407b870b15d0ba54bf3 to your computer and use it in GitHub Desktop.
public extension Array where Element: Equatable {
func find(other: Element) -> Element? {
for element in self {
if element == other {
return element
}
}
return nil
}
mutating func toggleElement(element: Element) {
if let hasIndex = self.indexOf(element) {
self.removeAtIndex(hasIndex)
}
else {
self.append(element)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment