Sha256: e576f93b0189b3a33121c043d1fe675f6c7cb20729cd2e7527a40e07559d3a18

Contents?: true

Size: 1.23 KB

Versions: 273

Compression:

Stored size: 1.23 KB

Contents

var baseAssignValue = require('./_baseAssignValue'),
    createAggregator = require('./_createAggregator');

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

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

/**
 * Creates an object composed of keys generated from the results of running
 * each element of `collection` thru `iteratee`. The corresponding value of
 * each key is the number of times the key was returned by `iteratee`. The
 * iteratee is invoked with one argument: (value).
 *
 * @static
 * @memberOf _
 * @since 0.5.0
 * @category Collection
 * @param {Array|Object} collection The collection to iterate over.
 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
 * @returns {Object} Returns the composed aggregate object.
 * @example
 *
 * _.countBy([6.1, 4.2, 6.3], Math.floor);
 * // => { '4': 1, '6': 2 }
 *
 * // The `_.property` iteratee shorthand.
 * _.countBy(['one', 'two', 'three'], 'length');
 * // => { '3': 2, '5': 1 }
 */
var countBy = createAggregator(function(result, value, key) {
  if (hasOwnProperty.call(result, key)) {
    ++result[key];
  } else {
    baseAssignValue(result, key, 1);
  }
});

module.exports = countBy;

Version data entries

273 entries across 271 versions & 29 rubygems

Version Path
clapton-0.0.19 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/lodash/countBy.js
immosquare-cleaner-0.1.49 node_modules/lodash/countBy.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/lodash/countBy.js
immosquare-cleaner-0.1.48 node_modules/lodash/countBy.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.6 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.5 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.4 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.3 lib/clapton/javascripts/node_modules/lodash/countBy.js
clapton-0.0.2 lib/clapton/javascripts/node_modules/lodash/countBy.js