Skip to content

Instantly share code, notes, and snippets.

@Luiz-N
Created July 16, 2014 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luiz-N/b1a00dc612274fc36cad to your computer and use it in GitHub Desktop.
Save Luiz-N/b1a00dc612274fc36cad to your computer and use it in GitHub Desktop.
`averageValues = (dim,attr) ->
reduceAddAvg = (attr) ->
(p,v) ->
++p.count
p.sum += +v[attr]
p.avg = p.sum/p.count
p
reduceRemoveAvg = (attr) ->
(p,v) ->
--p.count
p.sum -= +v[attr]
p.avg = p.sum/p.count
p
reduceInitAvg = () -> {count:0, sum:0, avg:0}
dim.group().reduce(reduceAddAvg(attr), reduceRemoveAvg(attr), reduceInitAvg)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment