Raw formula matches, e.g. from matchAll.
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;
}
Returns the most-likely-correct formula from a list of raw matches (highest scoreFormula, first match winning ties), or
undefinedwhen the list is empty.