What is the advantage of a for loop over map() in the 'Title Case a Sentence' algorithm and Other Questions?

Link to guide
I don’t understand why the intermediate solution is better than the basic solutions. Mainly:

  • why is it better to use a for loop rather than map()? What are the advantages?
  • is there an advantage to using charAt() rather than accessing the character via string[index]?

Also, below is my solution for this challenge that I came up with before looking at the guide. Any critiques would be helpful. Thank you!

function titleCase(str) {
  var words = str.toLowerCase().split(' ');
  words = words.map(function (word) {
    return word[0].toUpperCase() + word.slice(1,word.length);
  });
  return words.join(' ');
}

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

Thank you!

Do you know why fCC would choose to use charAt() instead of string[index]?