UNPKG

@modern-kit/utils

Version:
18 lines (14 loc) 430 B
'use strict'; var commonIdentity = require('../../common/identity/index.cjs'); function countBy(arr, iteratee) { const iterateeToUse = iteratee ?? commonIdentity.identity; const result = {}; for (let i = 0; i < arr.length; i++) { const value = arr[i]; const key = iterateeToUse(value); result[key] = (result[key] || 0) + 1; } return result; } exports.countBy = countBy; //# sourceMappingURL=index.cjs.map