compare static method

int compare(
  1. Value? x,
  2. Value? y
)

Compare two Values for sorting purposes.

Implementation

static int compare(Value? x, Value? y) {
  // Always sort null to the end of the list.
  if (x == null) {
    if (y == null) return 0;
    return 1;
  }
  if (y == null) return -1;

  // If either argument is a string, do a string comparison
  if (x is ValString || y is ValString) {
    var sx = x.toString();
    var sy = y.toString();
    return sx.compareTo(sy);
  }

  // If both arguments are numbers, compare numerically
  if (x is ValNumber && y is ValNumber) {
    double fx = (x).value;
    double fy = (y).value;
    if (fx < fy) return -1;
    if (fx > fy) return 1;
    return 0;
  }

  // Otherwise, consider all values equal, for sorting purposes.
  return 0;
}