code: function sortTerms(a, b) {
    if (a === b) {
      return 0;
    }
    // if no exponent, sort alphabetically
    if (a.indexOf('^') === -1) {
      return a < b ? -1 : 1;
    }
    // if exponent: sort by symbol, but then exponent decreasing
    else {
      const symbA = a.split('^')[0];
      const expA = a.split('^')[1];
      const symbB = b.split('^')[0];
      const expB = b.split('^')[1];
      if (symbA !== symbB) {
        return symbA < symbB ? -1 : 1;
      }
      else {
        return expA > expB ? -1 : 1;
      }
    }
  }
docs: Sort function for termnames. Sort first by symbol name, and then by exponent.