function createResultSorter(keys) {

  /**
   * @param {SearchResult} resultA
   * @param {SearchResult} resultB
   */
  return (resultA, resultB) => {
    let comparison = 0;

    // used to assign some priority to earlier keys
    let modifier = 1;

    for (const key of keys) {

      const tokenComparison = compareTokens(
        resultA.tokens[key],
        resultB.tokens[key]
      );

      if (tokenComparison !== 0) {
        comparison += tokenComparison * modifier;
        modifier *= 0.9;
        continue;
      }

      const stringComparison = compareStrings(
        resultA.item[ key ],
        resultB.item[ key ]
      );

      if (stringComparison !== 0) {
        comparison += stringComparison * modifier;
        modifier *= 0.9;
        continue;
      }
    }

    return comparison;
  };

}
Creates a compare function that can be used in Array.sort() based on a custom scoring function

@param {string[]} keys

@returns { (resultA: SearchResult, resultB: SearchResult) => number}