Skip to content

speed up diffKeys() with new Set() API #24

Open
@TechQuery

Description

@TechQuery

Document

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection
  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference

Target

web-utility/source/data.ts

Lines 121 to 138 in 0530fc2

export function diffKeys<T extends IndexKey>(oldList: T[], newList: T[]) {
const map = {} as Record<T, DiffStatus>;
for (const item of oldList) map[item] = DiffStatus.Old;
for (const item of newList) {
map[item] ||= 0;
map[item] += DiffStatus.New;
}
return {
map,
group: groupBy(
Object.entries<DiffStatus>(map),
([key, status]) => status
)
};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    To do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions