Tell us what’s happening:
I apologize for my frequent questions, but I don’t understand why the code fails to return the correct result when dealing with the “I’m a little tea pot” string
Your code so far
function titleCase(str) {
return str.toLowerCase().replace(/\b(\w)/g, r => r.toUpperCase());
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36.
I solved the problem by doing function titleCase(str) { return str.toLowerCase().replace(/\b(\w)/g, r => r.toUpperCase()).replace(/'m/i, m => m.toLowerCase()); }But that will only work for that specific example, are there any better ways of dealing with it?