Home

function: meanBy


meanBy(array: Array, iteratee: function): number

This method is like `mean` except that it accepts `iteratee` which is invoked for each element in `array` to generate the value to be averaged. The iteratee is invoked with one argument: (value).

Example(s):

const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]

meanBy(objects, ({ n }) => n)
// => 5

Params:

Name Type Attribute Description
array The array to iterate over.
iteratee The iteratee invoked per element.

Returns:

number

  {
    "comment": "/**\r\n * This method is like `mean` except that it accepts `iteratee` which is\r\n * invoked for each element in `array` to generate the value to be averaged.\r\n * The iteratee is invoked with one argument: (value).\r\n *\r\n * @since 4.7.0\r\n * @category Math\r\n * @param {Array} array The array to iterate over.\r\n * @param {Function} iteratee The iteratee invoked per element.\r\n * @returns {number} Returns the mean.\r\n * @example\r\n *\r\n * const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]\r\n *\r\n * meanBy(objects, ({ n }) => n)\r\n * // => 5\r\n */",
    "meta": {
        "range": [
            679,
            828
        ],
        "filename": "meanBy.js",
        "lineno": 23,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100006070",
            "name": "meanBy",
            "type": "FunctionDeclaration",
            "paramnames": [
                "array",
                "iteratee"
            ]
        },
        "vars": {
            "length": "meanBy~length"
        }
    },
    "description": "This method is like `mean` except that it accepts `iteratee` which is\rinvoked for each element in `array` to generate the value to be averaged.\rThe iteratee is invoked with one argument: (value).",
    "since": "4.7.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Math",
            "value": "Math"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "Array"
                ]
            },
            "description": "The array to iterate over.",
            "name": "array"
        },
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "The iteratee invoked per element.",
            "name": "iteratee"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "description": "Returns the mean."
        }
    ],
    "examples": [
        "const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]\r\rmeanBy(objects, ({ n }) => n)\r// => 5"
    ],
    "name": "meanBy",
    "longname": "meanBy",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000568",
    "___s": true,
    "filepath": "meanBy.js"
}