Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / countBy.js
1 var createAggregator = require('./internal/createAggregator');
2
3 /** Used for built-in method references. */
4 var objectProto = global.Object.prototype;
5
6 /** Used to check objects for own properties. */
7 var hasOwnProperty = objectProto.hasOwnProperty;
8
9 /**
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).
14  *
15  * @static
16  * @memberOf _
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.
21  * @example
22  *
23  * _.countBy([6.1, 4.2, 6.3], Math.floor);
24  * // => { '4': 1, '6': 2 }
25  *
26  * _.countBy(['one', 'two', 'three'], 'length');
27  * // => { '3': 2, '5': 1 }
28  */
29 var countBy = createAggregator(function(result, value, key) {
30   hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
31 });
32
33 module.exports = countBy;