Skip to main content
rule CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/js-set-map-lookups.md
Open on GitHub

What 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 items using a set of IDs

Example prompts for the agent

  • Review this code for repeated includes checks and switch them to a Set.
  • Rewrite the items filter so it checks IDs with Set.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.md

The paths frontmatter field limits the files

Step 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).

Similar IDE rules

All IDE rules for Programming languages →

From the same set20

The whole set →
js-min-max-loop js-min-max-loop instructs the agent to pick minimum or maximum values with a single loop instead of sorting. Avoids O(n log n) sorting costs and unnecessary array copies. CX Codex +1 ★ 1,064repo stars interview interview runs a long question-and-answer session about a plan file and writes the finished spec back to the same path. CX Codex +1 ★ 1,064repo stars js-cache-property-access js-cache-property-access guides Claude Code to store deep object properties and array bounds in local variables before executing JavaScript loops. CX Codex +1 ★ 1,064repo stars rendering-activity rendering-activity — a Claude rule that tells the agent to keep costly React components inside <Activity> so hiding them does not throw away state. CX Codex +1 ★ 1,064repo stars rendering-svg-precision rendering-svg-precision — a rule for Claude Code that reduces SVG coordinate precision to one decimal place. Applies when creating icons or editing graphics. CX Codex +1 ★ 1,064repo stars _template _template — a rule-file scaffold with fields for its title and impact, plus sections for contrasting incorrect and correct code. CX Codex +1 ★ 1,064repo stars async-parallel async-parallel — a Claude rule that sends independent async calls through Promise.all() instead of awaiting them one by one. Useful when a handler piles up sequential awaits. CX Codex +1 ★ 1,064repo stars rerender-derived-state The rerender-derived-state rule favors derived boolean state over continuously changing values, reducing React re-renders. It fits responsive UI logic. CX Codex +1 ★ 1,064repo stars

Project sponsors

Companies that keep this analytics open