List of utility methods to do Array Group By
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) { ... |