1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| // Inspired by Underscore's groupBy:
| // http://documentcloud.github.com/underscore/#groupBy
|
| "use strict";
|
| var callable = require("../../object/valid-callable")
| , value = require("../../object/valid-value")
| , forEach = Array.prototype.forEach
| , apply = Function.prototype.apply;
|
| module.exports = function (cb/*, thisArg*/) {
| var result;
|
| value(this);
| callable(cb);
|
| result = Object.create(null);
| forEach.call(
| this,
| function (item) {
| var key = apply.call(cb, this, arguments);
| if (!result[key]) result[key] = [];
| result[key].push(item);
| },
| arguments[1]
| );
| return result;
| };
|
|