Sha256: fc6fc00fe3b23df4de0327dc62a3745d2a1297ead4974d1de27b8d28a2c0ffa6

Contents?: true

Size: 1.31 KB

Versions: 61

Compression:

Stored size: 1.31 KB

Contents

var baseIteratee = require('./_baseIteratee'),
    createInverter = require('./_createInverter');

/** Used for built-in method references. */
var objectProto = Object.prototype;

/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;

/**
 * This method is like `_.invert` except that the inverted object is generated
 * from the results of running each element of `object` thru `iteratee`. The
 * corresponding inverted value of each inverted key is an array of keys
 * responsible for generating the inverted value. The iteratee is invoked
 * with one argument: (value).
 *
 * @static
 * @memberOf _
 * @since 4.1.0
 * @category Object
 * @param {Object} object The object to invert.
 * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
 * @returns {Object} Returns the new inverted object.
 * @example
 *
 * var object = { 'a': 1, 'b': 2, 'c': 1 };
 *
 * _.invertBy(object);
 * // => { '1': ['a', 'c'], '2': ['b'] }
 *
 * _.invertBy(object, function(value) {
 *   return 'group' + value;
 * });
 * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
 */
var invertBy = createInverter(function(result, value, key) {
  if (hasOwnProperty.call(result, value)) {
    result[value].push(key);
  } else {
    result[value] = [key];
  }
}, baseIteratee);

module.exports = invertBy;

Version data entries

61 entries across 60 versions & 7 rubygems

Version Path
sumomo-0.10.8 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.10.4 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.10.3 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.10.2 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.10.1 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.10.0 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.9.0 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.22 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.21 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.20 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.17 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.16 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.15 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.14 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.13 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.12 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.11 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.10 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.9 data/sumomo/api_modules/node_modules/lodash/invertBy.js
sumomo-0.8.8 data/sumomo/api_modules/node_modules/lodash/invertBy.js