"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const curry_1 = require("@arrows/composition/curry");
const _sort = (fn, arr) => [...arr].sort(fn);
const curriesSort = curry_1.default(_sort);
/**
 * Creates a new, sorted array.
 * Have built-in methods for sorting numerical and string arrays.
 *
 * @param compareFn Compare 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 using comparison operators
 * @method strDesc Sorts string arrays in a descending order  using comparison operators
 * @method locale Sorts string arrays in an ascending order using localeCompare
 * @method localeDesc Sorts string arrays in a descending order  using localeCompare
 */
const sort = Object.assign(curriesSort, {
    /**
     * Sorts numerical arrays in an ascending order
     *
     * @param arr Initial array
     * @returns New array
     */
    num: curriesSort((a, b) => a - b),
    /**
     * Sorts numerical arrays in a descending order
     *
     * @param arr Initial array
     * @returns New array
     */
    numDesc: curriesSort((a, b) => b - a),
    /**
     * Sorts string arrays in an ascending order using comparison operators.
     *
     * @param arr Initial array
     * @returns New array
     */
    str: curriesSort((a, b) => (a === b ? 0 : a > b ? 1 : -1)),
    /**
     * Sorts string arrays in a descending order using comparison operators.
     *
     * @param arr Initial array
     * @returns New array
     */
    strDesc: curriesSort((a, b) => a === b ? 0 : a > b ? -1 : 1),
    /**
     * Sorts string arrays in an ascending order using `String.prototype.localeCompare`.
     *
     * Uses String.prototype.localeCompare
     *
     * @param arr Initial array
     * @returns New array
     */
    locale: curriesSort((a, b) => a.localeCompare(b)),
    /**
     * Sorts string arrays in a descending order using `String.prototype.localeCompare`.
     *
     * @param arr Initial array
     * @returns New array
     */
    localeDesc: curriesSort((a, b) => b.localeCompare(a)),
});
exports.sort = sort;
exports.default = sort;
