by tlrobinson · 13y ago · 0 comments
var newArray = _.map(_.filter(array, function(item) {
return item % 2;
}), function(item) {
return item + 1;
});
vs newArray = (item + 1 for item in array when item % 2)
Uh huh. var newArray = _.chain(array).filter(function(item) {
return item % 2;
}).map(function(item) {
return item + 1;
}).value();
I often use CoffeeScript + Underscore var newArray = _(array).filter(function(item) {
return item % 2;
}).map(function(item) {
return item + 1;
});
Personally, I find this quite readable. And honestly, my comment was more about comparing CoffeeScript to its compiled JavaScript output, as is done in the slides. The compiled output is incredibly verbose and gives the false impression that JavaScript is always complicated.