Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

324 B
Raw Blame
export function deduplicateBy<TItem, TKey>(
  items: readonly TItem[],
  getKey: (item: TItem) => TKey,
): TItem[] {
  const byKey = new Map<TKey, TItem>();

  for (const item of items) {
    const key = getKey(item);

    if (!byKey.has(key)) {
      byKey.set(key, item);
    }
  }

  return Array.from(byKey.values());
}