Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save famousgarkin/b826b1ecefb7dcecf305 to your computer and use it in GitHub Desktop.
Save famousgarkin/b826b1ecefb7dcecf305 to your computer and use it in GitHub Desktop.
var Immutable = require('immutable');
describe('Immutable', function () {
it('can create nested groups', function () {
var items = [
{key1: 'a', key2: 'A'},
{key1: 'a', key2: 'A'},
{key1: 'a', key2: 'B'},
{key1: 'b', key2: 'A'},
{key1: 'b', key2: 'B'}
];
var result = Immutable.List(items)
.groupBy(function (item) {
return item.key1;
})
.map(function (items) {
return items.groupBy(function (item) {
return item.key2;
});
})
.toJS();
expect(result.a.A).toContain(items[0]);
expect(result.a.A).toContain(items[1]);
expect(result.a.B).toContain(items[2]);
expect(result.b.A).toContain(items[3]);
expect(result.b.B).toContain(items[4]);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment