Options
All
  • Public
  • Public/Protected
  • All
Menu

Module partition

Index

References

Functions Collection

References

Renames and re-exports partition

Collection Functions

  • partition<T>(collection: Record<string, T>, predicate: KeyIteratee | RecordIteratee<T, any>): T[][]
  • partition<T>(collection: T[], predicate: KeyIteratee | ArrayIteratee<T, any>): T[][]
  • 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).

    since

    5.11.0

    see

    groupBy, keyBy

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

    Type parameters

    • T

    Parameters

    • collection: Record<string, T>

      The collection to iterate over.

    • predicate: KeyIteratee | RecordIteratee<T, any>

      The function invoked per iteration.

    Returns T[][]

    Returns the array of grouped elements.

  • Type parameters

    • T

    Parameters

    • collection: T[]
    • predicate: KeyIteratee | ArrayIteratee<T, any>

    Returns T[][]