Almost there with this exercise. I need to convert a given string into the new format
Here Is My Handle Here Is My Spout
.
My code successfully returns
Here Is My Handle Here Is My Spout
. However, when I attempt to console.log(result.split(" "))
, it shows an extra empty string in the array: [ '', 'Here', 'Is', 'My', 'Handle', 'Here', 'Is', 'My', 'Spout' ]
.
I'm struggling to remove the empty string at index 0 and suspect that my function is returning an array of words rather than a single string.
function titleCase(str) {
const words = str.toLowerCase().split(" ");
let result = "";
for (let word of words) {
let firstCap = word.replace(word[0], word[0].toUpperCase());
result += " " + firstCap;
}
console.log(result.split(" "))
return result;
}
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));