UNPKG

975 BJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4/**
5 * Returns a copy of the list, sorted according to the comparator function,
6 * which should accept two values at a time and return a negative number if the
7 * first value is smaller, a positive number if it's larger, and zero if they
8 * are equal. Please note that this is a **copy** of the list. It does not
9 * modify the original.
10 *
11 * @func
12 * @memberOf R
13 * @since v0.1.0
14 * @category List
15 * @sig ((a, a) -> Number) -> [a] -> [a]
16 * @param {Function} comparator A sorting function :: a -> b -> Int
17 * @param {Array} list The list to sort
18 * @return {Array} a new array with its elements sorted by the comparator function.
19 * @example
20 *
21 * const diff = function(a, b) { return a - b; };
22 * R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7]
23 */
24
25
26var sort =
27/*#__PURE__*/
28_curry2(function sort(comparator, list) {
29 return Array.prototype.slice.call(list, 0).sort(comparator);
30});
31
32module.exports = sort;
\No newline at end of file