0

I recently did a coding challenge which requires you to take a string and capitalize the first letter of each word of the string and return the resulting string. Here is my solution:

String.prototype.toJadenCase = function () { 
  return this.split(" ").map(function(word){
    return word.charAt(0).toUpperCase() + word.slice(1);
  }).join(" ");
}

I understand the above perfectly, and feel that i am rather fimiliar with the map() method.

The below code uses a very similar syntax, the slight difference being the use of item => item[0]. What is this syntax and where can I read up on it ? My understanding is, instead of using 'word' in my case, it instead uses 'item' as a way to represent each 'mapped' word. But I am not familiar with the syntax of saying something => something[x] in JavaScript.

String.prototype.toJadenCase = function() {
  return this.split(' ').map(item => item[0].toUpperCase() + item.slice(1)).join(' ')
};
SGouws
  • 321
  • 1
  • 12

0 Answers0