Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var data = [ {type: "A", val:2},
             {type: "B", val:3},
             {type: "A", val:1},
             {type: "C", val:5} ];
console.log(data);
var groups = _(data).groupBy('type');
var out = _(groups).map(function(g, key) {
  return { 
     type: key, 
     val: _(g).reduce(function(m,x) { 
       return m + x.val;
     }, 0) 
  };
});
console.log(out);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
lazyberezovskypro
0viewers