728a6dabac3b9b075f3e2d38cad45ce6fd232cfe
[yaffs-website] / node_modules / grunt-legacy-log-utils / node_modules / lodash / groupBy.js
1 var createAggregator = require('./_createAggregator');
2
3 /** Used for built-in method references. */
4 var objectProto = 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 an array of elements responsible for generating the key.
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  * _.groupBy([6.1, 4.2, 6.3], Math.floor);
24  * // => { '4': [4.2], '6': [6.1, 6.3] }
25  *
26  * // The `_.property` iteratee shorthand.
27  * _.groupBy(['one', 'two', 'three'], 'length');
28  * // => { '3': ['one', 'two'], '5': ['three'] }
29  */
30 var groupBy = createAggregator(function(result, value, key) {
31   if (hasOwnProperty.call(result, key)) {
32     result[key].push(value);
33   } else {
34     result[key] = [value];
35   }
36 });
37
38 module.exports = groupBy;