react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / collection / countBy.js
80742 viewsvar createAggregator = require('../internal/createAggregator');12/** Used for native method references. */3var objectProto = Object.prototype;45/** Used to check objects for own properties. */6var hasOwnProperty = objectProto.hasOwnProperty;78/**9* Creates an object composed of keys generated from the results of running10* each element of `collection` through `iteratee`. The corresponding value11* of each key is the number of times the key was returned by `iteratee`.12* The `iteratee` is bound to `thisArg` and invoked with three arguments:13* (value, index|key, collection).14*15* If a property name is provided for `iteratee` the created `_.property`16* style callback returns the property value of the given element.17*18* If a value is also provided for `thisArg` the created `_.matchesProperty`19* style callback returns `true` for elements that have a matching property20* value, else `false`.21*22* If an object is provided for `iteratee` the created `_.matches` style23* callback returns `true` for elements that have the properties of the given24* object, else `false`.25*26* @static27* @memberOf _28* @category Collection29* @param {Array|Object|string} collection The collection to iterate over.30* @param {Function|Object|string} [iteratee=_.identity] The function invoked31* per iteration.32* @param {*} [thisArg] The `this` binding of `iteratee`.33* @returns {Object} Returns the composed aggregate object.34* @example35*36* _.countBy([4.3, 6.1, 6.4], function(n) {37* return Math.floor(n);38* });39* // => { '4': 1, '6': 2 }40*41* _.countBy([4.3, 6.1, 6.4], function(n) {42* return this.floor(n);43* }, Math);44* // => { '4': 1, '6': 2 }45*46* _.countBy(['one', 'two', 'three'], 'length');47* // => { '3': 2, '5': 1 }48*/49var countBy = createAggregator(function(result, value, key) {50hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);51});5253module.exports = countBy;545556