Ported Clojure’s group-by to CoffeeScript:

Array::group_by = (f) -&gt@reducece (r,x) ->

k = f x

r[k] = r[k] or []

r[k].push x

r

, {}