Created
December 20, 2016 17:16
-
-
Save bflannery/911ba8e00733129f105e508f569c2cbb to your computer and use it in GitHub Desktop.
Return the first letter of each word capitalized
This file contains 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
// Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case. | |
// For the purpose of this exercise, you should also capitalize connecting words like "the" and "of". | |
function titleCase(str) { | |
str = str.toLowerCase().split(' '); | |
for(var i=0; i < str.length; i++) { | |
str[i]= str[i].charAt(0).toUpperCase() + str[i].slice(1); | |
} | |
return str.join(' '); | |
} | |
console.log(titleCase("I'm a little tea pot")); | |
console.log(titleCase("sHoRt AnD sToUt")); | |
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment