1 var createAggregator = require('./_createAggregator');
3 /** Used for built-in method references. */
4 var objectProto = Object.prototype;
6 /** Used to check objects for own properties. */
7 var hasOwnProperty = objectProto.hasOwnProperty;
10 * Creates an object composed of keys generated from the results of running
11 * each element of `collection` through `iteratee`. The corresponding value
12 * of each key is the number of times the key was returned by `iteratee`.
13 * The iteratee is invoked with one argument: (value).
17 * @category Collection
18 * @param {Array|Object} collection The collection to iterate over.
19 * @param {Function|Object|string} [iteratee=_.identity] The iteratee to transform keys.
20 * @returns {Object} Returns the composed aggregate object.
23 * _.countBy([6.1, 4.2, 6.3], Math.floor);
24 * // => { '4': 1, '6': 2 }
26 * _.countBy(['one', 'two', 'three'], 'length');
27 * // => { '3': 2, '5': 1 }
29 var countBy = createAggregator(function(result, value, key) {
30 hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
33 module.exports = countBy;