INNER CODE UNIT · JavaScript

buildGallery

Manavarya09/design-extract · src/gallery/index.js:41

export function buildGallery(reports = []) {
  const seen = new Map();
  const items = [];
  for (const r of reports) {
    const item = toGalleryItem(r);
    // Disambiguate colliding slugs (two clones of the same host) deterministically.
    if (seen.has(item.slug)) {
      const n = seen.get(item.slug) + 1;
      seen.set(item.slug, n);
      item.slug = `${item.slug}-${n}`;
    } else {
      seen.set(item.slug, 1);
    }
    items.push(item);
  }

  items.sort((a, b) => (b.overall ?? -1) - (a.overall ?? -1));

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…