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