Skip to content

Instantly share code, notes, and snippets.

@jessesquires
Created June 27, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessesquires/7a0ad4abcf5de3fe2841 to your computer and use it in GitHub Desktop.
Save jessesquires/7a0ad4abcf5de3fe2841 to your computer and use it in GitHub Desktop.
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