Skip to content

Instantly share code, notes, and snippets.

@alex-cory
Last active August 13, 2017 21:52
Show Gist options
  • Save alex-cory/93248b76f220b245d7464ab11c273c8a to your computer and use it in GitHub Desktop.
Save alex-cory/93248b76f220b245d7464ab11c273c8a to your computer and use it in GitHub Desktop.
isAllUpperCase(word) isAllLowerCase(word) isCapitalizedOnly(word)
const isAllUp = s => s.match(/[^a-z]*/)[0].length === s.length
const isAllLow = s => s.match(/[a-z]*/)[0].length === s.length
const isCapitalized = s => s.substring(1, s.length).match(/[a-z]*/)[0].length === s.length - 1 && /^[A-Z]/.test(s)
console.log('All UP? expect: true got -> ', isAllUp('SOMEWORD'))
console.log('All UP? expect: false got -> ', isAllUp('Someword'))
console.log('All UP? expect: false got -> ', isAllUp('someword'))
console.log('All LOW? expect: true got -> ', isAllLow('someword'))
console.log('All LOW? expect: false got -> ', isAllLow('Someword'))
console.log('All LOW? expect: false got -> ', isAllLow('SOMEWORD'))
console.log('Capitalized? expect: true got -> ', isCapitalized('Someword'))
console.log('Capitalized? expect: false got -> ', isCapitalized('SOMEWORD'))
console.log('Capitalized? expect: false got -> ', isCapitalized('someword'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment