function compareObjects(x, y) {
    var keysX = Object.keys(x);
    var keysY = Object.keys(y); // compare keys

    keysX.sort(naturalSort);
    keysY.sort(naturalSort);
    var c = compareArrays(keysX, keysY);

    if (c !== 0) {
      return c;
    } // compare values


    for (var i = 0; i < keysX.length; i++) {
      var v = compareNatural(x[keysX[i]], y[keysY[i]]);

      if (v !== 0) {
        return v;
      }
    }

    return 0;
  }
Compare two objects

- First, compare sorted property names
- Next, compare the property values

@param {Object} x
@param {Object} y
@returns {number} Returns the comparison result: -1, 0, or 1