Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

partition

v4.17.15arrow_drop_down
v4.17.15
v4.17.11
STATUS
Passing
DOWNLOADS
141
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
4 months ago
SIZE
N/A
Creates an array of elements split into two groups, the first of which
2 contributors
Install partition as a package?
Copied
npm i @bit/lodash.lodash.partition
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
var users = [
  {
    user: "barney",
    age: 36,
    active: false,
  },
  {
    user: "fred",
    age: 40,
    active: true,
  },
  {
    user: "pebbles",
    age: 1,
    active: false,
modifieddraft
chevron_left
chevron_right
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
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']]
Arguments
collection: (Array | Object)

The collection to iterate over.

predicate: Function

The function invoked per iteration.

Returns
Array

Returns the array of grouped elements.