hey guys, i just finished this algorithm. I would like to have opinions on the, like if my aproach is the best one and if not how to improve it. Thanks!
function titleCase(str) {
var arr = [];
var splited = str.toLowerCase().split(" ");
console.log(splited);
for(var i = 0; i < splited.length; i++){
arr.push(splited[i].replace(/\w/, function(match){
return match.toUpperCase();
}));
}
return arr.join(" ");
}
titleCase("sHoRt AnD sToUt");
Here, .map() returns a new array of words whose first letters are uppercased versions of the split string.
By using arrow function syntax, this can be made more concise (although having two arrow functions in one line might look confusing if you’re not used to it)