Home

function: countBy


countBy(collection: Array, Object, iteratee: function): Object

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).

Example(s):

countBy([6.1, 4.2, 6.3], Math.floor)
// => { '4': 1, '6': 2 }

Params:

Name Type Attribute Description
collection The collection to iterate over.
iteratee The iteratee to transform keys.

Returns:

Object

  {
    "comment": "/**\r\n * Creates an object composed of keys generated from the results of running\r\n * each element of `collection` thru `iteratee`. The corresponding value of\r\n * each key is the number of times the key was returned by `iteratee`. The\r\n * iteratee is invoked with one argument: (value).\r\n *\r\n * @since 0.5.0\r\n * @category Collection\r\n * @param {Array|Object} collection The collection to iterate over.\r\n * @param {Function} iteratee The iteratee to transform keys.\r\n * @returns {Object} Returns the composed aggregate object.\r\n * @example\r\n *\r\n * countBy([6.1, 4.2, 6.3], Math.floor)\r\n * // => { '4': 1, '6': 2 }\r\n */",
    "meta": {
        "range": [
            824,
            1104
        ],
        "filename": "countBy.js",
        "lineno": 23,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100000906",
            "name": "countBy",
            "type": "FunctionDeclaration",
            "paramnames": [
                "collection",
                "iteratee"
            ]
        },
        "vars": {
            "": null
        }
    },
    "description": "Creates an object composed of keys generated from the results of running\reach element of `collection` thru `iteratee`. The corresponding value of\reach key is the number of times the key was returned by `iteratee`. The\riteratee is invoked with one argument: (value).",
    "since": "0.5.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Collection",
            "value": "Collection"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "Array",
                    "Object"
                ]
            },
            "description": "The collection to iterate over.",
            "name": "collection"
        },
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "The iteratee to transform keys.",
            "name": "iteratee"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "Object"
                ]
            },
            "description": "Returns the composed aggregate object."
        }
    ],
    "examples": [
        "countBy([6.1, 4.2, 6.3], Math.floor)\r// => { '4': 1, '6': 2 }"
    ],
    "name": "countBy",
    "longname": "countBy",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000095",
    "___s": true,
    "filepath": "countBy.js"
}