UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

25 lines (22 loc) 479 B
/*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ "use strict"; (() => { // src/groupBy.ts function groupBy(list, keyGetter) { const map = /* @__PURE__ */ new Map(); for (const item of list) { const key = keyGetter(item); const collection = map.get(key); if (collection) { collection.push(item); } else { map.set(key, [item]); } } return map; } })();