Home

function: partition


partition(collection: Array, Object, predicate: function): Array

Creates an array of elements split into two groups, the first of which contains elements `predicate` returns truthy for, the second of which contains elements `predicate` returns falsey for. The predicate is invoked with one argument: (value).

Example(s):

const users = [
  { 'user': 'barney',  'age': 36, 'active': false },
  { 'user': 'fred',    'age': 40, 'active': true },
  { 'user': 'pebbles', 'age': 1,  'active': false }
]

partition(users, ({ active }) => active)
// => objects for [['fred'], ['barney', 'pebbles']]

Params:

Name Type Attribute Description
collection The collection to iterate over.
predicate The function invoked per iteration.

Returns:

Array

  {
    "comment": "/**\r\n * Creates an array of elements split into two groups, the first of which\r\n * contains elements `predicate` returns truthy for, the second of which\r\n * contains elements `predicate` returns falsey for. The predicate is\r\n * invoked with one argument: (value).\r\n *\r\n * @since 3.0.0\r\n * @category Collection\r\n * @param {Array|Object} collection The collection to iterate over.\r\n * @param {Function} predicate The function invoked per iteration.\r\n * @returns {Array} Returns the array of grouped elements.\r\n * @see groupBy, keyBy\r\n * @example\r\n *\r\n * const users = [\r\n *   { 'user': 'barney',  'age': 36, 'active': false },\r\n *   { 'user': 'fred',    'age': 40, 'active': true },\r\n *   { 'user': 'pebbles', 'age': 1,  'active': false }\r\n * ]\r\n *\r\n * partition(users, ({ active }) => active)\r\n * // => objects for [['fred'], ['barney', 'pebbles']]\r\n */",
    "meta": {
        "range": [
            890,
            1065
        ],
        "filename": "partition.js",
        "lineno": 26,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100006938",
            "name": "partition",
            "type": "FunctionDeclaration",
            "paramnames": [
                "collection",
                "predicate"
            ]
        },
        "vars": {
            "": null
        }
    },
    "description": "Creates an array of elements split into two groups, the first of which\rcontains elements `predicate` returns truthy for, the second of which\rcontains elements `predicate` returns falsey for. The predicate is\rinvoked with one argument: (value).",
    "since": "3.0.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 function invoked per iteration.",
            "name": "predicate"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "Array"
                ]
            },
            "description": "Returns the array of grouped elements."
        }
    ],
    "see": [
        "groupBy, keyBy"
    ],
    "examples": [
        "const users = [\r  { 'user': 'barney',  'age': 36, 'active': false },\r  { 'user': 'fred',    'age': 40, 'active': true },\r  { 'user': 'pebbles', 'age': 1,  'active': false }\r]\r\rpartition(users, ({ active }) => active)\r// => objects for [['fred'], ['barney', 'pebbles']]"
    ],
    "name": "partition",
    "longname": "partition",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000642",
    "___s": true,
    "filepath": "partition.js"
}