Guest User

Untitled

a guest
Apr 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. let phrase: String = "If you know what you know if I..."
  2. let words = phrase.split(separator: " ")
  3.  
  4. /// Check if a given word is includen in a string
  5. /// before the own word.
  6. func containsWord(_ word: String, offsetLimit limit: Int) -> Bool
  7. {
  8. return words.enumerated()
  9. .filter({ $0.offset < limit })
  10. .map({ String($0.element) })
  11. .contains(word)
  12. }
  13.  
  14. for (index, word) in words.enumerated()
  15. {
  16. if containsWord(String(word), offsetLimit: index)
  17. {
  18. print("The first word duplicated is \(word)")
  19. break
  20. }
  21. }
Add Comment
Please, Sign In to add comment