Last active
October 4, 2015 15:41
-
-
Save julianshen/bf4895ab31f4fbda09c4 to your computer and use it in GitHub Desktop.
Array Extension
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
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