"use strict";
// @ts-nocheck
exports.__esModule = true;
exports.groupBy = exports.chunk = exports.range = exports.putBefore = exports.updateAt = exports.sortBy = void 0;
var tslib_1 = require("tslib");
var sortBy = function (array, param, order, sortFn) {
    if (order === void 0) { order = 'asc'; }
    if (sortFn === void 0) { sortFn = function (a, b) { return (a < b ? -1 : 1); }; }
    var compareFn = function (a, b) {
        return (order === 'desc' ? -1 : 1) * sortFn(a[param], b[param]);
    };
    return (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(array), false).sort(compareFn);
};
exports.sortBy = sortBy;
var updateAt = function (array, index, newItem, isExpand) {
    if (isExpand === void 0) { isExpand = false; }
    var fixedIndex = index < 0 ? 0 : index;
    if (fixedIndex >= array.length) {
        return isExpand ? (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(array), false), [newItem], false) : array;
    }
    return (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(array.slice(0, fixedIndex)), false), [
        newItem
    ], false), (0, tslib_1.__read)(array.slice(fixedIndex + (isExpand ? 0 : 1), array.length)), false);
};
exports.updateAt = updateAt;
var putBefore = function (array, index, newItem) {
    return (0, exports.updateAt)(array, index, newItem, true);
};
exports.putBefore = putBefore;
var range = function (n) { return (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(Array(n).keys()), false); };
exports.range = range;
var chunk = function (array, size) {
    var index = 0;
    var resIndex = 0;
    var result = [];
    while (index < array.length) {
        result[resIndex++] = array.slice(index, (index += size));
    }
    return result;
};
exports.chunk = chunk;
var groupBy = function (array, iteratee) {
    return array.reduce(function (result, value) {
        var _a;
        var key = iteratee(value);
        return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, result), (_a = {}, _a[key] = result[key] ? (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(result[key]), false), [value], false) : [value], _a));
    }, {});
};
exports.groupBy = groupBy;
