Skip to content

add groupBy

something like https://gist.github.com/ryanguill/82b348f72378c5a58821b07a0e294e9d

function groupBy (column, data) {
    if (isNull(arguments.data)) {
        return function (data) {
            return groupBy(column, arguments.data);
        };
    }
    return data.reduce(function (agg, row) {
        var key = row[column];
        if (isNull(agg[key])) {
            agg[key] = { count: 0, rows: [] };
        }
        agg[key]["count"] += 1;
        arrayAppend(agg[key]["rows"], row);
        return agg;
    }, {});
}

This should work for queries or arrays of structs. Could also consider making it optionally case sensitive on the grouping column. And error handling if the grouping column doesnt exist in the row.