Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function upperCase(str)
- {
- return str.toUpperCase();
- }
- function titleCase(str)
- {
- // 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.
- // Finally return str to all lowercase then replace method applied with previous upperCase function only the first letter.
- var firstLetter = /(^|\s)[a-z]/g;
- return str.toLowerCase().replace(firstLetter, upperCase);
- }
- console.log(titleCase("HERE IS ALL CAPS"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement