ChemPal Documentation - v1.6.0
    Preparing search index...

    Function findDuplicateProductIds

    • Finds product identities that appear more than once, keyed by productIdentity (ignoring the positional _id). This is detection, not repair: the same product appearing twice means the search almost certainly ran twice, so callers surface it rather than silently removing the duplicates.

      Parameters

      • results: Product[]

        The products to scan.

      Returns string[]

      The duplicated identities (empty when every product is unique).

      findDuplicateProductIds([{ id: "A" }, { id: "A" }, { id: "B" }]); // ["id:A"]
      
      export function findDuplicateProductIds(results: Product[]): string[] {
      const seen = new Set<string>();
      const duplicates = new Set<string>();
      for (const product of results) {
      const key = productIdentity(product);
      if (seen.has(key)) {
      duplicates.add(key);
      } else {
      seen.add(key);
      }
      }
      return [...duplicates];
      }