Title Case a Sentence m

Title Case a Sentence m
0

#1
function titleCase(str) {
  let spt = str.split(" ");
  let newArr= "";
spt.map((n)=> {
  let l ="";
  for(let i=1;i<n.length;i++){
    l+= n[i].toLowerCase();
  }
  return (n[0].toUpperCase() +l );
});
console.log(spt);
for(let j=0;j<spt.length;j++){
newArr = newArr + spt[j] + " ";
}
  return newArr;
}

titleCase("I'm a little tea pot");

what is the problem .? why it is not working ? please help me somone
:frowning:


#2

why I can not complete this with array.map() ??? :frowning:


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4

thanks… but help me now in my code please.


#5

Hi.

Not sure if your code will pass the test, but you do have a small issue in your function.
Your map is being done, but since it is not assigned to a variable, its discarded (useless).
So just need to modify this line:
spt=spt.map((n)=> {
Now, when you execute it, this is the result (according to your code):

(5) ["I'm", "A", "Little", "Tea", "Pot"]
"I'm A Little Tea Pot "

Cheers !