public
Last active

d3 data array to summary object (e.g., "SELECT x, count(*) FROM y GROUP BY x")

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10
// 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}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.