Dev Helpers

UI Components / Statistics and data displays

Find a candidate's strongest rank

Dev Helpers · July 12, 2025

A candidate's strongest rank is the smallest numeric position among valid ballots. Handle a missing candidate before converting an index into a rank.

Worked example

<style>
  dl {
    display: grid;
    gap: 0.6rem;
    margin: 0;
  }
  dl > div {
    display: grid;
    gap: 0.35rem;
    padding: 0.6rem;
    border-bottom: 1px solid #bbb;
  }
  dt {
    font-weight: 700;
  }
  dd {
    margin: 0;
    overflow-wrap: anywhere;
  }
  @media (min-width: 32rem) {
    dl > div {
      grid-template-columns: minmax(5rem, 1fr) 3fr;
    }
  }
</style>
<h2>Find a candidate's strongest rank</h2>
<details>
  <summary>Input records</summary>
  <pre>
[
  {
    "name": "Ada",
    "picks": [
      "A",
      "C",
      "B"
    ]
  },
  {
    "name": "Kim",
    "picks": [
      "C",
      "A",
      "B"
    ]
  },
  {
    "name": "Leo",
    "picks": [
      "A",
      "B",
      "C"
    ]
  }
]</pre>
</details>
<dl class="" id="result"></dl>
<script>
  const rows = [
    { name: "Ada", picks: ["A", "C", "B"] },
    { name: "Kim", picks: ["C", "A", "B"] },
    { name: "Leo", picks: ["A", "B", "C"] },
  ];
  const result = Math.min(...rows.map((r) => r.picks.indexOf("C") + 1));
  const list = document.querySelector("#result");
  list.replaceChildren();
  for (const [key, value] of Object.entries(
    typeof result === "object" && result !== null ? result : { value: result },
  )) {
    const row = document.createElement("div");
    const label = document.createElement("dt");
    label.textContent = key;
    const detail = document.createElement("dd");
    detail.textContent =
      typeof value === "string" ? value : JSON.stringify(value);
    row.append(label, detail);
    list.append(row);
  }
  if (!list.children.length) list.after("No matching entries.");
</script>

Implementation notes

A candidate absent from the data has no observed rank. Giving that candidate rank zero would incorrectly place them above the winner.

Try it yourself

Remove the candidate from one ballot and inspect how an absent index behaves.

Open the UI Components example →

Editorial date July 12, 2025 · Published December 6, 2026

Related articles

Large headline statistic

A prominent statistic needs a unit, scope and timeframe. A large number alone gives a reader little basis for comparison.

Article byline

A byline combines authorship and dates without competing with the headline. Use a machine-readable time value alongside the visible date.

Audio episode transcript card

An episode transcript serves readers who cannot or prefer not to play audio. Identify speakers in text and keep the transcript easy to navigate.