I’ve tested each of the test cases in my function, and each result is identical to the test case result. What is causing this the tests to fail when I run it?
Here’s the code:
function titleCase(str) {
// regex patterns
let eachWordRegex = /(?!'.*')\b[\w']+\b/gi;
let eachWord = str.match(eachWordRegex);
let firstLetter = "";
let otherLetters = "";
let newArray = [];
for (let i = 0; i < eachWord.length; i++){
firstLetter = eachWord[i].slice(0,1);
otherLetters = eachWord[i].slice(1);
newArray.push(firstLetter.toUpperCase() + otherLetters.toLowerCase());
}
let newStr = newArray.join(" ")+".";
console.log(newStr);
return newStr;
}
titleCase("sHoRt AnD sToUt");