_compareAscending.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var isSymbol = require('./isSymbol');
  2. /**
  3. * Compares values to sort them in ascending order.
  4. *
  5. * @private
  6. * @param {*} value The value to compare.
  7. * @param {*} other The other value to compare.
  8. * @returns {number} Returns the sort order indicator for `value`.
  9. */
  10. function compareAscending(value, other) {
  11. if (value !== other) {
  12. var valIsDefined = value !== undefined,
  13. valIsNull = value === null,
  14. valIsReflexive = value === value,
  15. valIsSymbol = isSymbol(value);
  16. var othIsDefined = other !== undefined,
  17. othIsNull = other === null,
  18. othIsReflexive = other === other,
  19. othIsSymbol = isSymbol(other);
  20. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  21. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  22. (valIsNull && othIsDefined && othIsReflexive) ||
  23. (!valIsDefined && othIsReflexive) ||
  24. !valIsReflexive) {
  25. return 1;
  26. }
  27. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  28. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  29. (othIsNull && valIsDefined && valIsReflexive) ||
  30. (!othIsDefined && valIsReflexive) ||
  31. !othIsReflexive) {
  32. return -1;
  33. }
  34. }
  35. return 0;
  36. }
  37. module.exports = compareAscending;