Title Case a Sentence - antoniojvargas/FreeCodeCamp GitHub Wiki
Title Case a Sentence
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".
Remember to use Read-Search-Ask if you get stuck. Write your own code.
function titleCase(str) {
var arrayOfStrings = str.split(" ");
for(var i = 0; i < arrayOfStrings.length; i++){
if(arrayOfStrings[i].length > 1){
arrayOfStrings[i] = arrayOfStrings[i].charAt(0).toUpperCase() +
arrayOfStrings[i].slice(1, arrayOfStrings[i].length).toLowerCase();
} else {
arrayOfStrings[i] = arrayOfStrings[i].toUpperCase();
}
}
str = arrayOfStrings.join(" ");
return str;
}
titleCase("sHoRt AnD sToUt");