CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
countBy.js41 linesDownload Raw Back to lodash
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 corresponding value of13 * each key is the number of times the key was returned by `iteratee`. The14 * iteratee is invoked with one argument: (value).15 *16 * @static17 * @memberOf _18 * @since 0.5.019 * @category Collection20 * @param {Array|Object} collection The collection to iterate over.21 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.22 * @returns {Object} Returns the composed aggregate object.23 * @example24 *25 * _.countBy([6.1, 4.2, 6.3], Math.floor);26 * // => { '4': 1, '6': 2 }27 *28 * // The `_.property` iteratee shorthand.29 * _.countBy(['one', 'two', 'three'], 'length');30 * // => { '3': 2, '5': 1 }31 */32var countBy = createAggregator(function(result, value, key) {33  if (hasOwnProperty.call(result, key)) {34    ++result[key];35  } else {36    baseAssignValue(result, key, 1);37  }38});39 40module.exports = countBy;41 
basant307/AI_Governance_Project · CoolFace