About js-set-map-lookups
A JavaScript coding skill for replacing repeated array membership checks with Set or Map lookups. It is intended for developers optimizing repeated checks in code.
Key features
- 01Replace array membership checks with Set
- 02Use Map for repeated lookups
- 03Reduce repeated checks from O(n) to O(1)
Use cases
- 01Filter items against a list of allowed IDs
- 02Speed up repeated membership checks
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ theorcdev/ 8bitcn-ui --skill js-set-map-lookupsAfter installing, type/js-set-map-lookupsin Claude Code to confirm it loaded.
Details
From the project READMEUse Set/Map for O(1) Lookups
Convert arrays to Set/Map for repeated membership checks.
Incorrect (O(n) per check):
const allowedIds = ['a', 'b', 'c', ...]
items.filter(item => allowedIds.includes(item.id))
Correct (O(1) per check):
const allowedIds = new Set(['a', 'b', 'c', ...])
items.filter(item => allowedIds.has(item.id))
Comments
Markdown supported