Alright, this almost works… I’ve seen others use the .split method as recommended in the challenge, but I almost found another way to do this using a Regex. The issue I’m having is that the \b meta-character is viewing apostrophes as a space, and as a result, it capitalizes the M in I’m. Is there way to stop it from doing this? I’ve tried several combinations using a Regex builder, but to no avail. Here is what I have so far…
function titleCase(str) {
//Convert all cases to lowercase.
str = str.toLowerCase();
//Convert each first letter to uppercase.
str = str.replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
return str;
}
titleCase("I'm a little tea pot");