After I’ve done some research and struggled my way through this challenge I feel like there has to be a more efficient way to solve this. My questions is if this code ‘good enough’ or is there something I could do that would be more reasonable?
Any help or suggestions on how to improve my code would be greatly appreciated.
Your code so far
function titleCase(str) {
let newStr = str.toLowerCase().split(" ");
for(let i = 0; i < newStr.length; i++){
newStr[i] = newStr[i].replace(newStr[i].charAt(0), newStr[i].charAt(0).toUpperCase());
}
return newStr.join(" ").replace(",", " ");
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.