Curried function that returns a map (object) with keys derived by applying each array element to the given identity function. The value(s) at each key will be an array of elements whose identity matches the given key.
npm install array-groupby --save
You can also use Duo, Bower or download the files manually.
var groupBy = require('array-groupby')
var strings = [ 'two', 'birds', 'three', 'green', 'peas' ]
groupBy('length', strings)
//=> { '3': [ 'two' ], '4': [ 'peas' ], '5': [ 'birds', 'three', 'green' ] }
var groupBy = require('array-groupby')
var strings = Promise.resolve([ 'two', 'birds', 'three', 'green', 'peas' ])
var charAt0 = string => string[0]
strings.then(groupBy(charAt0))
//=> { t: [ 'two', 'three' ], b: [ 'birds' ], g: [ 'green' ], p: [ 'peas' ] }
fn (Function|String)
Function to apply to each element.list (array)
Array to evaluate.
(Object)
Object with keys derived by applying each array element to the given identity function.
SEE: contributing.md