Please comment on my solution to the Title Case problem

Below is my code. Is it straight forward or should I focus on simplifying it? I feel like I don’t make my code as simple as it can be:

function titleCase(str) {
var strArray = [];
var newArray = [];
strArray = str.split(" ");

newArray = strArray.map(function(val) {
return val.toLowerCase();
});

for (i = 0; i < newArray.length; i++) {
newArray[i] = newArray[i].charAt(0).toUpperCase() + newArray[i].substr(1, newArray[i].length);
}

return newArray.join(" ");
}

//Any feedback would be greatly appreciated!

Hi SolaScriptura92, the approach to the problem is good but only two tips:

  1. You don’t need a newArray to do the text transform
  2. You can do more than one operation in your map () callback, why you don’t do the trasform directly on val?

Good work :wink:

Good point! Thank you so much! Your feedback is greatly appreciated! :smiley: