function titleCase(str) {
return str
.split(' ')
.map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase())
.join(' ');
}
console.log(titleCase("I'm a little tea pot")); // I'm A Little tea Pot
function titleCase(str) {
return str.toLowerCase().replace(/(^|s)S/g, L => L.toUpperCase());
}
function titleCase(sentence) {
let sentence = string.toLowerCase().split(" ");
for (let i = 0; i < sentence.length; i++) {
sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1);
}
return sentence.join(" ");
}
const reverseTitleCase = (string) => {
const newText = string
.toLowerCase()
.split(" ")
.map(function(item) {
return item.slice(0, -1) + item.slice(-1).toUpperCase();
})
.join(" ");
return newText;
};