code: function (f, direction) {
  
          if (typeof (f) !== 'function') {
              var 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
              var 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;
      }
docs: code from https://github.com/Teun/thenBy.js has its own tests /* $lab:coverage:off$