mcpField
J
js-set-map-lookups

js-set-map-lookups

github.com/theorcdevDevelopment2.1k39 installsUpdated 3d ago
Repository

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

  1. 01Replace array membership checks with Set
  2. 02Use Map for repeated lookups
  3. 03Reduce repeated checks from O(n) to O(1)

Use cases

  1. 01Filter items against a list of allowed IDs
  2. 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-lookups

After installing, type/js-set-map-lookupsin Claude Code to confirm it loaded.

Details

From the project README

Use 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