Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let phrase: String = "If you know what you know if I..."
- let words = phrase.split(separator: " ")
- /// Check if a given word is includen in a string
- /// before the own word.
- func containsWord(_ word: String, offsetLimit limit: Int) -> Bool
- {
- return words.enumerated()
- .filter({ $0.offset < limit })
- .map({ String($0.element) })
- .contains(word)
- }
- for (index, word) in words.enumerated()
- {
- if containsWord(String(word), offsetLimit: index)
- {
- print("The first word duplicated is \(word)")
- break
- }
- }
Add Comment
Please, Sign In to add comment