LendAndRegret/node_modules/es-toolkit/dist/array/uniqBy.mjs
2026-05-02 17:27:43 +08:00

14 lines
308 B
JavaScript

function uniqBy(arr, mapper) {
const map = new Map();
for (let i = 0; i < arr.length; i++) {
const item = arr[i];
const key = mapper(item, i, arr);
if (!map.has(key)) {
map.set(key, item);
}
}
return Array.from(map.values());
}
export { uniqBy };