ChemPal Documentation - v1.6.0
    Preparing search index...
    • Returns the most-likely-correct formula from a list of raw matches (highest scoreFormula, first match winning ties), or undefined when the list is empty.

      Parameters

      • candidates: string[]

        Raw formula matches, e.g. from matchAll.

      Returns undefined | string

      The best candidate, or undefined.

      pickBestFormula(["IN", "CS", "NaOSOCH3"]); // "NaOSOCH3"
      
      export function pickBestFormula(candidates: string[]): string | undefined {
      let best: string | undefined;
      let bestScore = -Infinity;
      for (const candidate of candidates) {
      const score = scoreFormula(candidate);
      if (score > bestScore) {
      bestScore = score;
      best = candidate;
      }
      }
      return best;
      }