Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

28 linhas
958 B

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