UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

26 lines (21 loc) 465 B
'use strict'; /*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ // 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; } exports.groupBy = groupBy;