json-groupby.js
function collectProperties(groups, properties) { 
  var collection = {};
  for (var key in groups) {
    if (Array.isArray(groups[key])) {
      collection[key] = groups[key].reduce(function(coll, item) {
        properties.forEach(function(prop) { 
          if (!coll[prop]) coll[prop] = [];
          coll[prop] = coll[prop].concat(propertyAt(item,prop));
        })
        return coll;
      }, {})
    } else {
      collection[key] = collectProperties(groups[key], properties);
    }
  }
  return collection;
}
function collectProperties(groups, properties) { 
  var collection = {};
  for (var key in groups) {
    if (Array.isArray(groups[key])) {
      collection[key] = groups[key].reduce(function(coll, item) {
        properties.forEach(function(prop) { 
          if (!coll[prop]) coll[prop] = [];
          coll[prop] = coll[prop].concat(propertyAt(item,prop));
        })
        return coll;
      }, {})
    } else {
      collection[key] = collectProperties(groups[key], properties);
    }
  }
  return collection;
}
function collectProperties ( groups , properties ) { var collection = { } ; for ( var key in groups ) { if ( Array . isArray ( groups [ key ] ) ) { collection [ key ] = groups [ key ] . reduce ( function ( coll , item ) { properties . forEach ( function ( prop ) { if ( ! coll [ prop ] ) coll [ prop ] = [ ] ; coll [ prop ] = coll [ prop ] . concat ( propertyAt ( item , prop ) ) ; } ) return coll ; } , { } ) } else { collection [ key ] = collectProperties ( groups [ key ] , properties ) ; } } return collection ; }
collect the properties in an array
collect the properties in an array