I solved problem in normal procedure method using nested for loops.
I am getting space between letters not words.
but we need space between words to pass the test.
Question link below:
function titleCase(str) {
let arr = str.toLowerCase().split(' ');
let final = [];
for(let i=0; i<arr.length; i++){
final.push(arr[i][0].toUpperCase());
for(let j=1; j<arr[i].length; j++){
final.push(arr[i][j].toLowerCase());
}
}
return final.join('');
}
console.log(titleCase("I'm a little tea pot"));
Take another look and you will see that you are pushing each letter to the array, one at a time. There are no spaces between the different indexes of the array. The array then gets joined together and you get a string with no spaces.
Try using one final.push and concatenate the uppercase first letter with the rest of the array.
Yes you are right @c0deblack my second for loop is pushing
single letter each time. By the using this method arr[i][0].toUpperCase() + arr[i].slice(1);
i got the answer with all tests passing
Thank you.