https://github.com/devgateway/underscore-groups-by
A many-to-many version of underscore's _.groupBy
https://github.com/devgateway/underscore-groups-by
Last synced: 7 months ago
JSON representation
A many-to-many version of underscore's _.groupBy
- Host: GitHub
- URL: https://github.com/devgateway/underscore-groups-by
- Owner: devgateway
- Created: 2014-08-25T16:27:28.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-25T16:28:30.000Z (over 11 years ago)
- Last Synced: 2025-07-06T08:05:40.482Z (7 months ago)
- Language: JavaScript
- Size: 105 KB
- Stars: 0
- Watchers: 19
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Underscore GroupsBy Mixin
=========================
A many-to-many version of [underscore's `_.groupBy`](http://underscorejs.org/#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
```bash
$ npm install groups-by
```
Browserify Example
------------------
```javascript
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...
```javascript
console.log(grouped);
```
should yield
```javascript
{
1: [
{n: [1], name: 'alice'},
{n: [1, 2], name: 'alob'}
],
2: [
{n: [2], name: 'bob'},
{n: [1, 2], name: 'alob'}
]
}
```
License
-------
MIT