🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

underscore-groups-by

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

underscore-groups-by

Many-to-many grouping of objects in a list.

0.0.1
latest
Source
npm
Version published
Weekly downloads
13
62.5%
Maintainers
1
Weekly downloads
 
Created
Source

Underscore GroupsBy Mixin

A many-to-many version of underscore's _.groupBy.

Install

This module should work with plain old javascript, browserify, and requirejs.

For regular javascript, make sure you include it after underscore. Underscore is the only dependency.

For browserify and requirejs, you need to require it, but you don't need to do anything with the return value if you don't want -- it will mix itself into underscore for you.

Install with npm

$ npm install groups-by

Browserify Example


var _ = require('underscore');
require('underscore-groups-by');


var things = [
  {n: [1], name: 'alice'},
  {n: [2], name: 'bob'},
  {n: [1, 2], name: 'alob'}
];

var grouped = _(things).groupsBy(function (thing) {
  return thing.n;  // return value must be an array
});

logging the result...

console.log(grouped);

should yield

{
  1: [
    {n: [1], name: 'alice'},
    {n: [1, 2], name: 'alob'}
  ],
  2: [
    {n: [2], name: 'bob'},
    {n: [1, 2], name: 'alob'}
  ]
}

License

MIT

Keywords

underscore

FAQs

Package last updated on 25 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts