function titleCase(str) {
str = str.toLowerCase();
let regx = /[a-z']+/g;
let words = str.match(regx);
let modifiedStr = "";
for (let i = 0; i < words.length; i++) {
modifiedStr += words[i].replace(words[i][0], words[i][0].toUpperCase()) + " ";
}
return modifiedStr;
}
console.log(titleCase("I'm a little tea pot"));
console.log(titleCase("sHoRt AnD sToUt"));
output> I’m A Little Tea Pot
output> Short And Stout