Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. extension CollectionType where Self.Generator.Element == String {
  2. func find(subString:String) -> Int {
  3. for (i,s) in self.enumerate() {
  4. if s.containsString(subString) {
  5. return i
  6. }
  7. }
  8. return -1
  9. }
  10. }
  11.  
  12. extension CollectionType where Self.Generator.Element == Int {
  13. func find(i:Int) -> Int {
  14. for n in self {
  15. if n == i {
  16. return n
  17. }
  18. }
  19. return -1
  20. }
  21. }
  22.  
  23. let a = ["1222", "abdc", " anc abc", "abc abc", "123"]
  24. let b = [1, 2, 3, 5, 5, 6, 9, 10]
  25.  
  26. a.find("abc")
  27. b.find(11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement