Skip to content

Instantly share code, notes, and snippets.

@julianshen
Last active October 4, 2015 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianshen/bf4895ab31f4fbda09c4 to your computer and use it in GitHub Desktop.
Save julianshen/bf4895ab31f4fbda09c4 to your computer and use it in GitHub Desktop.
Array Extension
extension CollectionType where Generator.Element == String {
func find(subString:Generator.Element) -> Int {
for (i,s) in self.enumerate() {
if s.containsString(subString) {
return i
}
}
return -1
}
}
extension CollectionType where Generator.Element == Int {
func find(i:Generator.Element) -> Int {
for n in self {
if n == i {
return n
}
}
return -1
}
}
let a = ["1222", "abdc", " anc abc", "abc abc", "123"]
let b = [1, 2, 3, 5, 5, 6, 9, 10]
a.find("abc")
b.find(11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment