Nodejs Utililty Methods Array Group By

List of utility methods to do Array Group By

Description

The list of methods to do Array Group By are organized into topic(s).

Method

groupBy(prop)
Array.prototype.groupBy = function(prop) {
  return this.reduce(function(groups, item) {
    var val = item[prop];
    groups[val] = groups[val] || [];
    groups[val].push(item);
    return groups;
  }, {});
let students = [
...
groupBy(selector, comparer)
Array.prototype.groupBy = function (selector, comparer) {
    var grp = [];
    var l = this.length;
    comparer = comparer || EqualityComparer;
    selector = selector || Selector;
    for (var i = 0; i < l; i++) {
        var k = selector(this[i]);
        var g = grp.first(function (u) { return comparer(u.key, k); });
        if (!g) {
...