makeCompareFunction = function (f, direction) {
    if (typeof f !== 'function') {
      const prop = f;
      // make unary function
      f = function (v1) {
        return v1[prop];
      };
    }

    if (f.length === 1) {
      // f is a unary function mapping a single item to its sort score
      const uf = f;
      f = function (v1, v2) {
        return uf(v1) < uf(v2) ? -1 : uf(v1) > uf(v2) ? 1 : 0;
      };
    }

    if (direction === -1) {
      return function (v1, v2) {
        return -f(v1, v2);
      };
    }

    return f;
  }
get chained functions for sorting

@return {Function}