Skip to content

Instantly share code, notes, and snippets.

@uruly
Last active April 12, 2018 05:34
Show Gist options
  • Save uruly/5786b7d527888d863ef5d929515bdec3 to your computer and use it in GitHub Desktop.
Save uruly/5786b7d527888d863ef5d929515bdec3 to your computer and use it in GitHub Desktop.
extension Array {
func findIndex(includeElement: (Element) -> Bool) -> [Int] {
var indexArray:[Int] = []
for (index, element) in enumerated() {
if includeElement(element) {
indexArray.append(index)
}
}
return indexArray
}
func findAll(includeElement: (Element) -> Bool) -> [(Int, Element)] {
let seq = zip(0..<self.count, self)
return seq.filter() { includeElement($0.1) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment