Dev Helpers
← Back

Build the first departure board

Build the first departure board. Start with typed records and inspect the inferred result.

Open this example in the interactive library

Source code

type Row = { line: string; start: number; end: number };
const rows: Row[] = [
  { line: "Red", start: 8, end: 10 },
  { line: "Blue", start: 9, end: 11 },
  { line: "Red", start: 12, end: 15 },
  { line: "Gold", start: 15, end: 16 },
];
const result = Object.fromEntries(
  rows.toSorted((a, b) => b.start - a.start).map((r) => [r.line, r.start]),
);
console.log(JSON.stringify(result, null, 2));

Sample output

{
  "Gold": 15,
  "Red": 8,
  "Blue": 9
}