basant307/AI_Governance_Project
048
1var baseAssignValue = require('./_baseAssignValue'),2 createAggregator = require('./_createAggregator');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 * Creates an object composed of keys generated from the results of running12 * each element of `collection` thru `iteratee`. The order of grouped values13 * is determined by the order they occur in `collection`. The corresponding14 * value of each key is an array of elements responsible for generating the15 * key. The iteratee is invoked with one argument: (value).16 *17 * @static18 * @memberOf _19 * @since 0.1.020 * @category Collection21 * @param {Array|Object} collection The collection to iterate over.22 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.23 * @returns {Object} Returns the composed aggregate object.24 * @example25 *26 * _.groupBy([6.1, 4.2, 6.3], Math.floor);27 * // => { '4': [4.2], '6': [6.1, 6.3] }28 *29 * // The `_.property` iteratee shorthand.30 * _.groupBy(['one', 'two', 'three'], 'length');31 * // => { '3': ['one', 'two'], '5': ['three'] }32 */33var groupBy = createAggregator(function(result, value, key) {34 if (hasOwnProperty.call(result, key)) {35 result[key].push(value);36 } else {37 baseAssignValue(result, key, [value]);38 }39});40 41module.exports = groupBy;42 