basant307/AI_Governance_Project
048
1var baseIteratee = require('./_baseIteratee'),2 createInverter = require('./_createInverter');3 4/** Used for built-in method references. */5var objectProto = Object.prototype;6 7/** Used to check objects for own properties. */8var hasOwnProperty = objectProto.hasOwnProperty;9 10/**11 * Used to resolve the12 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)13 * of values.14 */15var nativeObjectToString = objectProto.toString;16 17/**18 * This method is like `_.invert` except that the inverted object is generated19 * from the results of running each element of `object` thru `iteratee`. The20 * corresponding inverted value of each inverted key is an array of keys21 * responsible for generating the inverted value. The iteratee is invoked22 * with one argument: (value).23 *24 * @static25 * @memberOf _26 * @since 4.1.027 * @category Object28 * @param {Object} object The object to invert.29 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.30 * @returns {Object} Returns the new inverted object.31 * @example32 *33 * var object = { 'a': 1, 'b': 2, 'c': 1 };34 *35 * _.invertBy(object);36 * // => { '1': ['a', 'c'], '2': ['b'] }37 *38 * _.invertBy(object, function(value) {39 * return 'group' + value;40 * });41 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }42 */43var invertBy = createInverter(function(result, value, key) {44 if (value != null &&45 typeof value.toString != 'function') {46 value = nativeObjectToString.call(value);47 }48 49 if (hasOwnProperty.call(result, value)) {50 result[value].push(key);51 } else {52 result[value] = [key];53 }54}, baseIteratee);55 56module.exports = invertBy;57 