Skip to content

Instantly share code, notes, and snippets.

@kardeiz
Created October 23, 2012 19:40
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 kardeiz/3941080 to your computer and use it in GitHub Desktop.
Save kardeiz/3941080 to your computer and use it in GitHub Desktop.
d3 data array to summary object (e.g., "SELECT x, count(*) FROM y GROUP BY x")
// This may not be the most efficient way to do this, but it's pretty clean
var yourObject = d3.nest()
.key(function(d) { return d; })
.rollup(function(d) { return d.length; })
.map(yourArray);
// e.g.,
// var input = ["this","is","a","test","for","this","method"];
// var output = {"this":2,"is":1,"a":1,"test":1,"for":1,"method":1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment