"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const curry_1 = require("@arrows/composition/curry");
const _sortBy_ = (compareFn, mappingFn, arr) => {
    return [...arr].sort((a, b) => compareFn(mappingFn(a), mappingFn(b)));
};
const curriedSortBy_ = curry_1.default(_sortBy_);
/**
 * Creates a new, sorted array.
 * Accepts mapping function that maps values before comparing
 * (mapping does not affect actual values of the array).
 * Have built-in methods for sorting numerical and alphabetical sorting.
 *
 * @param compareFn Compare function
 * @param mappingFn Mapping function
 * @param arr Initial array
 * @returns New array
 *
 * @method num Sorts numerical arrays in an ascending order
 * @method numDesc Sorts numerical arrays in a descending order
 * @method str Sorts string arrays in an ascending order
 * @method strDesc Sorts string arrays in a descending order
 * @method locale Sorts string arrays in an ascending order using localeCompare
 * @method localeDesc Sorts string arrays in a descending order  using localeCompare
 */
const sortBy_ = Object.assign(curriedSortBy_, {
    /**
     * Sorts numerical arrays in an ascending order
     *
     * @param mappingFn Mapping function
     * @param arr Initial array
     * @returns New array
     */
    num: curriedSortBy_((a, b) => a - b),
    /**
     * Sorts numerical arrays in a descending order
     *
     * @param mappingFn Mapping function
     * @param arr Initial array
     * @returns New array
     */
    numDesc: curriedSortBy_((a, b) => b - a),
    /**
     * Sorts string arrays in an ascending order using comparison operators.
     *
     * @param mappingFn Mapping function
     * @param arr Initial array
     * @returns New array
     */
    str: curriedSortBy_((a, b) => a.localeCompare(b)),
    /**
     * Sorts string arrays in a descending order using comparison operators.
     *
     * @param mappingFn Mapping function
     * @param arr Initial array
     * @returns New array
     */
    strDesc: curriedSortBy_((a, b) => b.localeCompare(a)),
    /**
     * Sorts string arrays in an ascending order using `String.prototype.localeCompare`.
     *
     * @param mappingFn Mapping function
     * @param arr Initial array
     * @returns New array
     */
    locale: curriedSortBy_((a, b) => a.localeCompare(b)),
    /**
     * Sorts string arrays in a descending order using `String.prototype.localeCompare`.
     *
     * @param mappingFn Mapping function
     * @param arr Initial array
     * @returns New array
     */
    localeDesc: curriedSortBy_((a, b) => b.localeCompare(a)),
});
exports.sortBy_ = sortBy_;
exports.default = sortBy_;
