@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
23 lines (18 loc) • 456 B
JavaScript
;
/*!
* @techmely/utils
* Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
* MIT Licensed
*/
// src/partition/index.ts
function partition(arr, fn) {
return arr.reduce((acc, val, i, arr2) => {
const current = fn(val, i, arr2);
if (acc.has(current))
acc.get(current).push(val);
else
acc.set(current, [val]);
return acc;
}, /* @__PURE__ */ new Map()).values();
}
exports.partition = partition;