Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/components/src/ui/data-table-filter/lib/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,19 @@ function deepEqual(a: unknown, b: unknown): boolean {
export function uniq<T>(arr: T[]): T[] {
// Use a Map where key is the deep hash and value is an array of items sharing the same hash.
const seen = new Map<string, T[]>();
const primitives = new Set<unknown>();
const result: T[] = [];

for (const item of arr) {
const type = typeof item;
if (item === null || (type !== 'object' && type !== 'function')) {
if (!primitives.has(item)) {
primitives.add(item);
result.push(item);
}
continue;
}

const hash = deepHash(item);
if (seen.has(hash)) {
// There is a potential duplicate; check the stored items with the same hash.
Expand Down