mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(desktop): index unique positional key values directly (#17316)
This commit is contained in:
@@ -38,19 +38,15 @@ const sequenceStarts = (members: readonly Record<string, string>[]) => {
|
||||
|
||||
/** Each member another attribute's value names alone among `members`, by that attribute and value. */
|
||||
const aloneBy = (members: readonly Record<string, string>[], other: string) => {
|
||||
const counts = new Map<string, number>();
|
||||
for (const member of members) {
|
||||
// A negative index marks a value that occurs more than once.
|
||||
const indexes = new Map<string, number>();
|
||||
for (const [index, member] of members.entries()) {
|
||||
const value = member[other];
|
||||
if (value !== undefined) counts.set(value, (counts.get(value) ?? 0) + 1);
|
||||
if (value !== undefined)
|
||||
indexes.set(value, indexes.has(value) ? -1 : index);
|
||||
}
|
||||
return new Map(
|
||||
members.flatMap((member, index) => {
|
||||
const value = member[other];
|
||||
return value !== undefined && counts.get(value) === 1
|
||||
? [[value, index] as const]
|
||||
: [];
|
||||
}),
|
||||
);
|
||||
for (const [value, index] of indexes) if (index === -1) indexes.delete(value);
|
||||
return indexes;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user