Today I crossed some piece of code that I needed to refactor. It took me a while to understand what exactly this method does:
priceStatuses = -> base = _.map(_.select(workitems, (w)-> w.priceStatus && w.priceStatus.length), (w)-> w.priceStatus) base.push "Estimated", "Confirmed", "As per Quotation" uniqued = _.uniq base _.sortBy uniqued, (v)-> v
So I decided to rewrite making use of underscore's beautiful API
priceStatuses = -> _(workitems) .select (w)-> w.priceStatus && w.priceStatus.length .map('priceStatus') .push("Estimated", "Confirmed", "As per Quotation") .uniq() .sort() .value()
The drawback is that you have to add that
value() call at the very end to stop the chainability, otherwise it won't work.
But when you get more than 2 methods in a row I think it pays off on readability :)