Created
June 27, 2015 20:59
-
-
Save jessesquires/7a0ad4abcf5de3fe2841 to your computer and use it in GitHub Desktop.
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 String { | |
var isHomogeneous: Bool { | |
guard !isEmpty else { return true } | |
for i in startIndex..<endIndex.predecessor() { | |
if characters[i] != characters[i.successor()] { | |
return false | |
} | |
} | |
return true | |
} | |
} | |
assert("aaa".isHomogeneous) | |
assert("😎😎".isHomogeneous) | |
assert("😎".isHomogeneous) | |
assert("".isHomogeneous) | |
assert("as".isHomogeneous == false) | |
assert(" </del>~".isHomogeneous == false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment