Basic Algorithm Scripting - Title Case a Sentence

Tell us what’s happening:
Please review my code

Your code so far

function titleCase(str) {
  let setText = str.split(" ");
  let mapText = => x.toUpperCase());
  for (let i = 0; i < mapText.length; i++) {
    let laterText = mapText[i].slice(1);
  setText[i] = mapText[i][0] + laterText.toLowerCase();

 return setText.join(" ");

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Algorithm Scripting - Title Case a Sentence

Link to the challenge:

It seems quite complicated for something this simple.
Try to rewrite to use one for loop only (no map or slice. Think about it, how would a kid with this sentence and a piece of paper solve this one)

Also you can try to do it with a single map that takes a single lambda function. (Might be harder than above though).

Finally, please indent your code properly…(especially when asking for a review)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.