source: imaps-frontend/node_modules/lodash-es/invertBy.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import baseIteratee from './_baseIteratee.js';
2import createInverter from './_createInverter.js';
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 the
12 * [`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 generated
19 * from the results of running each element of `object` thru `iteratee`. The
20 * corresponding inverted value of each inverted key is an array of keys
21 * responsible for generating the inverted value. The iteratee is invoked
22 * with one argument: (value).
23 *
24 * @static
25 * @memberOf _
26 * @since 4.1.0
27 * @category Object
28 * @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 * @example
32 *
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
56export default invertBy;
Note: See TracBrowser for help on using the repository browser.