1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var is_array_1 = require("./is-array");
|
4 | var is_function_1 = require("./is-function");
|
5 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
6 | function groupBy(data, condition) {
|
7 | if (!condition || !is_array_1.default(data)) {
|
8 | return {};
|
9 | }
|
10 | var result = {};
|
11 |
|
12 | var predicate = is_function_1.default(condition) ? condition : function (item) { return item[condition]; };
|
13 | var key;
|
14 | for (var i = 0; i < data.length; i++) {
|
15 | var item = data[i];
|
16 | key = predicate(item);
|
17 | if (hasOwnProperty.call(result, key)) {
|
18 | result[key].push(item);
|
19 | }
|
20 | else {
|
21 | result[key] = [item];
|
22 | }
|
23 | }
|
24 | return result;
|
25 | }
|
26 | exports.default = groupBy;
|
27 |
|
\ | No newline at end of file |