@tc39-proposal/group-by
Version:
TC39 proposal: Implementation of Object.groupBy and Map.groupBy
2 lines (1 loc) • 547 B
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).TC39GroupBy={})}(this,(function(e){"use strict";function n(e,n){return e.reduce(((e,t,o)=>{const u=n(t,o);return e.has(u)?e.get(u).push(t):e.set(u,[t]),e}),new Map)}function t(e,n){return e.reduce(((e,t,o)=>{const u=n(t,o);return e[u]?e[u].push(t):e[u]=[t],e}),{})}e.groupBy=function(e,o,u){return u?n(e,o):t(e,o)},e.groupByMap=n,e.groupByObject=t}));