Created
June 10, 2016 10:56
-
-
Save Gujci/d497ca7f64b84407b870b15d0ba54bf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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