1 var baseIteratee = require('./_baseIteratee'),
2 createInverter = require('./_createInverter');
4 /** Used for built-in method references. */
5 var objectProto = Object.prototype;
7 /** Used to check objects for own properties. */
8 var hasOwnProperty = objectProto.hasOwnProperty;
11 * This method is like `_.invert` except that the inverted object is generated
12 * from the results of running each element of `object` through `iteratee`.
13 * The 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).
20 * @param {Object} object The object to invert.
21 * @param {Function|Object|string} [iteratee=_.identity] The iteratee invoked per element.
22 * @returns {Object} Returns the new inverted object.
25 * var object = { 'a': 1, 'b': 2, 'c': 1 };
28 * // => { '1': ['a', 'c'], '2': ['b'] }
30 * _.invertBy(object, function(value) {
31 * return 'group' + value;
33 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
35 var invertBy = createInverter(function(result, value, key) {
36 if (hasOwnProperty.call(result, value)) {
37 result[value].push(key);
39 result[value] = [key];
43 module.exports = invertBy;