Dev Helpers
← Back

Roll back a batch of held seat codes

Roll back a batch of held seat codes. Start with typed records and inspect the inferred result.

Open this example in the interactive library

Source code

type Row = { row: string; seat: number; held: boolean };
const rows: Row[] = [
  { row: "A", seat: 1, held: true },
  { row: "A", seat: 2, held: false },
  { row: "B", seat: 1, held: false },
  { row: "B", seat: 2, held: false },
];
const result = rows.map((r) =>
  ["A1", "B2"].includes(r.row + r.seat) ? { ...r, held: false } : r,
);
console.log(JSON.stringify(result, null, 2));

Sample output

[
  {
    "row": "A",
    "seat": 1,
    "held": false
  },
  {
    "row": "A",
    "seat": 2,
    "held": false
  },
  {
    "row": "B",
    "seat": 1,
    "held": false
  },
  {
    "row": "B",
    "seat": 2,
    "held": false
  }
]