var _ = require("lodash");

var data = [
  {
    id: 1,
    name: "A",
    age: 18
  },
  {
    id: 2,
    name: "B",
    age: 20
  },
  {
    id: 3,
    name: "A",
    age: 22
  },
  {
    id: 4,
    name: "B",
    age: 17
  },
];

var group_by_name = _.groupBy(data, 'name');
print("group_by_name: ", JSON.stringify(group_by_name, null, ' '));
var group_by_age = _.groupBy(data, function(item){
  return Math.floor(item.age / 10);
});
print("group_by_age: ", JSON.stringify(group_by_age, null, ' '));