// @ts-nocheck
import { __assign, __read, __spreadArray } from "tslib";
export 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 __spreadArray([], __read(array), false).sort(compareFn);
};
export 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 ? __spreadArray(__spreadArray([], __read(array), false), [newItem], false) : array;
    }
    return __spreadArray(__spreadArray(__spreadArray([], __read(array.slice(0, fixedIndex)), false), [
        newItem
    ], false), __read(array.slice(fixedIndex + (isExpand ? 0 : 1), array.length)), false);
};
export var putBefore = function (array, index, newItem) {
    return updateAt(array, index, newItem, true);
};
export var range = function (n) { return __spreadArray([], __read(Array(n).keys()), false); };
export 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;
};
export var groupBy = function (array, iteratee) {
    return array.reduce(function (result, value) {
        var _a;
        var key = iteratee(value);
        return __assign(__assign({}, result), (_a = {}, _a[key] = result[key] ? __spreadArray(__spreadArray([], __read(result[key]), false), [value], false) : [value], _a));
    }, {});
};
