Dev Helpers
← Back

Group document IDs by contributor

Group document IDs by contributor. Inspect the transformed data in the console.

Open this example in the interactive library

Source code

const rows = [
  { doc: "guide", rev: 1, author: "Ada" },
  { doc: "api", rev: 1, author: "Leo" },
  { doc: "guide", rev: 3, author: "Kim" },
  { doc: "guide", rev: 4, author: "Ada" },
];
const result = Object.fromEntries(
  [...new Set(rows.map((r) => r.author))].map((author) => [
    author,
    [...new Set(rows.filter((r) => r.author === author).map((r) => r.doc))],
  ]),
);
console.log(JSON.stringify(result, null, 2));

Sample output

{
  "Ada": [
    "guide"
  ],
  "Leo": [
    "api"
  ],
  "Kim": [
    "guide"
  ]
}