Saturday, December 24, 2022
A function to determine if the usage of capitals in a word is correct.
import "strings"
func detectCapitalUse(word string) bool {
// all lowercase
if (strings.ToLower(word) == word) {
return true
}
// all uppercase
if (strings.ToUpper(word) == word) {
return true
}
// from second letter lowercase
if (strings.ToLower(word[1:]) == word[1:]) {
return true
}
return false
}