reports/frontend/node_modules/es-toolkit/dist/compat/array/countBy.mjs
jtricerolph 1c411e402e Add settings page for managing forecasting API key and URL via UI
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 14:37:36 +00:00

17 lines
593 B
JavaScript

import { isArrayLike } from "../predicate/isArrayLike.mjs";
import { iteratee } from "../util/iteratee.mjs";
//#region src/compat/array/countBy.ts
function countBy(collection, iteratee$1) {
if (collection == null) return {};
const array = isArrayLike(collection) ? Array.from(collection) : Object.values(collection);
const mapper = iteratee(iteratee$1 ?? void 0);
const result = Object.create(null);
for (let i = 0; i < array.length; i++) {
const item = array[i];
const key = mapper(item);
result[key] = (result[key] ?? 0) + 1;
}
return result;
}
//#endregion
export { countBy };