timoxley / functional-javascript-workshop

A functional javascript workshop. No libraries required (i.e. no underscore), just ES5.
2.06k stars 441 forks source link

Item 4) Why aren't anonymous arrow functions being proudly advertized? #187

Open switheyw opened 7 years ago

switheyw commented 7 years ago

First off: Thanks a whole lot to timoxley and others who took a lot of time out of their busy days to create this self-paced functional-javascript learning app. I'm finding it very useful. A lot of my Javascript learning is book learning or is used on largish apps which have to get finished, leaving me with little time to experiment.

I think my function (below) is very easy to read. I've been watching Professor. Frisby's lessons on Egghead and he encourages top to bottom readability in chained functions.

function getShortMessages(messages) {
   return  messages
          .map( json => json.message)
          .filter( sentence =>  sentence.length < 50 )
}

When I looked provided answer, I couldn't easily follow the logic flow. I assume that the best examples of their kind should be added to the functional javascript workshop so that we don't get beginners off on the wrong foot.

function getShortMessages(messages) {
   return messages.filter(function(item) {
     return item.message.length < 50
       }).map(function(item) {
          return item.message
       })
}

Let's propagate anonymous arrow functions. I believe that the ES6 transformers available will produce code which can run everywhere.

Stephen Wright