Last active
August 6, 2020 15:42
-
-
Save tmm/a65837676afce88138985c09a04e7a4a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import UIKit | |
| //"USA", return true | |
| //"Calvin", return true | |
| //"compUter", return false | |
| //"coding", return true | |
| func isUppercase(character: Character) -> Bool { | |
| String(character) == character.uppercased() | |
| } | |
| func isCorrectCapitalization(_ string: String) -> Bool { | |
| var prevChar: Character? | |
| for char in string { | |
| if prevChar != nil && | |
| isUppercase(character: char) && | |
| !isUppercase(character: prevChar!) { | |
| return false | |
| } | |
| prevChar = char | |
| } | |
| return true | |
| } | |
| isCorrectCapitalization("USA") == true | |
| isCorrectCapitalization("Calvin") == true | |
| isCorrectCapitalization("compUter") == false | |
| isCorrectCapitalization("coding") == true | |
| isCorrectCapitalization("HELLO") == true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment