Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / globule / node_modules / lodash / invertBy.js
1 var baseIteratee = require('./_baseIteratee'),
2     createInverter = require('./_createInverter');
3
4 /** Used for built-in method references. */
5 var objectProto = Object.prototype;
6
7 /** Used to check objects for own properties. */
8 var hasOwnProperty = objectProto.hasOwnProperty;
9
10 /**
11  * This method is like `_.invert` except that the inverted object is generated
12  * from the results of running each element of `object` thru `iteratee`. The
13  * corresponding inverted value of each inverted key is an array of keys
14  * responsible for generating the inverted value. The iteratee is invoked
15  * with one argument: (value).
16  *
17  * @static
18  * @memberOf _
19  * @since 4.1.0
20  * @category Object
21  * @param {Object} object The object to invert.
22  * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
23  * @returns {Object} Returns the new inverted object.
24  * @example
25  *
26  * var object = { 'a': 1, 'b': 2, 'c': 1 };
27  *
28  * _.invertBy(object);
29  * // => { '1': ['a', 'c'], '2': ['b'] }
30  *
31  * _.invertBy(object, function(value) {
32  *   return 'group' + value;
33  * });
34  * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
35  */
36 var invertBy = createInverter(function(result, value, key) {
37   if (hasOwnProperty.call(result, value)) {
38     result[value].push(key);
39   } else {
40     result[value] = [key];
41   }
42 }, baseIteratee);
43
44 module.exports = invertBy;