group-by

v1.0.0arrow_drop_down
v1.0.0
v0.0.1
STATUS
Passing
DOWNLOADS
58,776
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
7 years ago
SIZE
603 B
Creates an object composed of keys generated from the results of running each element of `collection` thru `iteratee`.
2 contributors
Install group-by as a package?
Copied
npm i @bit/bit.utils.object.group-by
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
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
No preview available
modifieddraft
chevron_left
chevron_right
groupBy (
collection:(Array | Object),
iteratee:Function
) : Object

Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The order of grouped values is determined by the order they occur in collection. The corresponding value of each key is an array of elements responsible for generating the key. The iteratee is invoked with one argument: (value).

Example
groupBy([6.1, 4.2, 6.3], Math.floor)
// => { '4': [4.2], '6': [6.1, 6.3] }
Arguments
collection: (Array | Object)

The collection to iterate over.

iteratee: Function

The iteratee to transform keys.

Returns
Object

Returns the composed aggregate object.

Test Summary

group-by the groupBy function should exist

Pass

group-by should group by the floored value (4, 6)

Pass
Help and resources