js-set-map-lookups — Claude Code rule: what it does, how to install
The js-set-map-lookups rule recommends using a Set when code repeatedly checks array membership. It applies to repeated lookups, such as filtering items by ID.
no license ★ 1,064 updated 2026-01-21
.claude/rules/js-set-map-lookups.mdWhat js-set-map-lookups does
An includes call scans an array, so repeating that check means repeating a linear search. The rule shows how to build a Set from allowed values and test membership with has; its example filters items using item.id.
For Claude Code, place the rule at .claude/rules/js-set-map-lookups.md. The advice targets repeated checks; the example does not establish a need to convert an array used for a single lookup. The sample is JavaScript with TypeScript annotations.
What it helps with
- replace repeated array scans with set lookups
- check whether an item ID belongs to an allowed list
- filter
itemsusing a set of IDs
Example prompts for the agent
- Review this code for repeated
includeschecks and switch them to aSet. - Rewrite the
itemsfilter so it checks IDs withSet.has. - Find repeated membership checks in this code and apply the rule.
How to install js-set-map-lookups
Manually: put the files in place
.claude/rules/js-set-map-lookups.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/js-set-map-lookups.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/js-set-map-lookups.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/js-set-map-lookups.mdManually: put the files in place
.clinerules/js-set-map-lookups.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about js-set-map-lookups
How do I install js-set-map-lookups in Claude Code?
Add the rule file at .claude/rules/js-set-map-lookups.md.
What does js-set-map-lookups do?
It recommends checking repeated membership with a Set rather than scanning an array with includes. The example uses has while filtering items.
Why use Set.has instead of includes here?
The example gives includes a per-check cost of O(n), while the Set lookup is shown as O(1).