source: trip-planner-front/node_modules/lodash/groupBy.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
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 running
12 * each element of `collection` thru `iteratee`. The order of grouped values
13 * is determined by the order they occur in `collection`. The corresponding
14 * value of each key is an array of elements responsible for generating the
15 * key. The iteratee is invoked with one argument: (value).
16 *
17 * @static
18 * @memberOf _
19 * @since 0.1.0
20 * @category Collection
21 * @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 * @example
25 *
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;
Note: See TracBrowser for help on using the repository browser.