Created
September 29, 2015 11:38
-
-
Save waltzaround/8db28418015484f5157d to your computer and use it in GitHub Desktop.
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
function titleCase(str) { | |
var newstr = str.split(" ");//split whatever input we have been given using the split object... | |
for(i=0;i<newstr.length;i++){ //as we cycle through each newly separated string in the array... | |
newstr[i] = newstr[i].charAt(0).toUpperCase() + newstr[i].substring(1).toLowerCase(); | |
// we take the first character in the string and capitalize it, and each subsequent character in the separated word lowercase | |
} | |
newstr = newstr.join(" "); // now that we are done, join the strings from the array back together | |
return newstr // output finished result as we are done with the titleCase function | |
} | |
titleCase("I'm a little tea pot", ""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment