Function partition

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

    Type Parameters

    • T

    Parameters

    • collection: Record<string, T>

      The collection to iterate over.

    • predicate: KeyIteratee | RecordIteratee<T>

      The function invoked per iteration.

    Returns T[][]

    Returns the array of grouped elements.

    5.11.0

    [[groupBy]], [[keyBy]]

    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']]
  • 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).

    Type Parameters

    • T

    Parameters

    • collection: T[]

      The collection to iterate over.

    • predicate: KeyIteratee | ArrayIteratee<T>

      The function invoked per iteration.

    Returns T[][]

    Returns the array of grouped elements.

    5.11.0

    [[groupBy]], [[keyBy]]

    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']]