baseCompareAscending.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * The base implementation of `compareAscending` which compares values and
  3. * sorts them in ascending order without guaranteeing a stable sort.
  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 baseCompareAscending(value, other) {
  11. if (value !== other) {
  12. var valIsNull = value === null,
  13. valIsUndef = value === undefined,
  14. valIsReflexive = value === value;
  15. var othIsNull = other === null,
  16. othIsUndef = other === undefined,
  17. othIsReflexive = other === other;
  18. if ((value > other && !othIsNull) || !valIsReflexive ||
  19. (valIsNull && !othIsUndef && othIsReflexive) ||
  20. (valIsUndef && othIsReflexive)) {
  21. return 1;
  22. }
  23. if ((value < other && !valIsNull) || !othIsReflexive ||
  24. (othIsNull && !valIsUndef && valIsReflexive) ||
  25. (othIsUndef && valIsReflexive)) {
  26. return -1;
  27. }
  28. }
  29. return 0;
  30. }
  31. module.exports = baseCompareAscending;