Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. function upperCase(str)
  2. {
  3. return str.toUpperCase();
  4. }
  5.  
  6. function titleCase(str)
  7. {
  8. // Use regex ^|\s to start at beginning of string or match whitespace in the string. [a-z]/g to match all lowercase letter class globally.
  9. // Finally return str to all lowercase then replace method applied with previous upperCase function only the first letter.
  10.  
  11. var firstLetter = /(^|\s)[a-z]/g;
  12. return str.toLowerCase().replace(firstLetter, upperCase);
  13. }
  14.  
  15. console.log(titleCase("HERE IS ALL CAPS"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement