Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/lodash/countBy.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

40 lines (36 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |