Dev Helpers
← Back

Transpose ballots into rank columns

Transpose ballots into rank columns. Inspect the transformed data in the console.

Open this example in the interactive library

Source code

const rows = [
  { name: "Ada", picks: ["A", "C", "B"] },
  { name: "Kim", picks: ["C", "A", "B"] },
  { name: "Leo", picks: ["A", "B", "C"] },
];
const result = rows[0].picks.map((_, i) => rows.map((r) => r.picks[i]));
console.log(JSON.stringify(result, null, 2));

Sample output

[
  [
    "A",
    "C",
    "A"
  ],
  [
    "C",
    "A",
    "B"
  ],
  [
    "B",
    "B",
    "C"
  ]
]