Skip to main content
rule CX Codex

js-index-maps — Claude Code rule: what it does, how to install

The js-index-maps rule replaces repeated .find() calls on one key with a Map index. Use it when array lookups happen many times.

MIT ★ 7,191 updated 2026-10-24

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

What js-index-maps does

The rule recommends creating a Map once when code repeatedly searches for records by the same key. For instance, users can be indexed by id, then retrieved for each order with get() instead of scanning the users array with .find() again.

Building the index costs O(n), while later Map reads cost O(1). With 1000 orders and 1000 users, the example changes 1M operations to 2K. Keeping .find() inside the order loop leaves every lookup at O(n).

What it helps with

  • replace repeated .find() calls by one key
  • index users by id
  • cut lookup work while processing orders
  • spot linear searches inside loops

Example prompts for the agent

  • Review the order-processing code and replace repeated .find() calls by userId with a Map.
  • Index users by id, then rewrite the user lookup to use get().
  • Look for repeated searches by the same key and suggest a Map-based refactor.

How to install js-index-maps

Manually: put the files in place

.claude/rules/js-index-maps.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-index-maps

How do I install js-index-maps in Claude Code?

Put the rule in .claude/rules/js-index-maps.md.

What does js-index-maps do?

It tells the agent to replace repeated .find() calls for one key with a single Map index and get() lookups.

Why use a Map instead of repeated .find() here?

The index is built in O(n), while each later lookup is O(1). In the example, 1000 orders and 1000 users change 1M operations to 2K.

Source text

js-index-maps.md · MIT
---
title: Build Index Maps for Repeated Lookups
impact: LOW-MEDIUM
impactDescription: 1M ops to 2K ops
tags: javascript, map, indexing, optimization, performance
---

## Build Index Maps for Repeated Lookups

Multiple `.find()` calls by the same key should use a Map.

**Incorrect (O(n) per lookup):**

```typescript
function processOrders(orders: Order[], users: User[]) {
  return orders.map(order => ({
    ...order,
    user: users.find(u => u.id === order.userId)
  }))
}
```

**Correct (O(1) per lookup):**

```typescript
function processOrders(orders: Order[], users: User[]) {
  const userById = new Map(users.map(u => [u.id, u]))

  return orders.map(order => ({
    ...order,
    user: userById.get(order.userId)
  }))
}
```

Build map once (O(n)), then all lookups are O(1).
For 1000 orders × 1000 users: 1M ops → 2K ops.

© tech-leads-club · MIT · tech-leads-club/agent-skills

Similar IDE rules

All IDE rules for Code review and refactoring →

From the same set130

The whole set →
codenavi codenavi guides the AI through unfamiliar codebases, plans surgical edits, and stores project discoveries in .notebook/. Useful for debugging and refactoring without guesswork. CX Codex +1 327installs decomposition-planning-roadmap decomposition-planning-roadmap is a Claude Code skill that maps out monolith decomposition and migration. It activates for service extraction planning, work prioritization, and progress tracking. CX Codex +1 322installs seo Walks Claude through technical and on-page SEO: crawl rules, canonicals, sitemaps, meta tags, JSON-LD. Useful when pages don't get indexed or snippets look broken. CX Codex +1 ★ 7,191repo stars best-practices best-practices is a Claude Code skill for checking web code security, browser compatibility, and code quality. It runs on requests for a security review or code modernization. CX Codex +1 ★ 7,191repo stars rendering-hydration-suppress-warning rendering-hydration-suppress-warning silences hydration warnings where the two renders are meant to differ: timestamps, per-render IDs, dates formatted for the visitor's locale. CX Codex +1 ★ 7,191repo stars bundle-defer-third-party bundle-defer-third-party prevents third-party trackers from inflating the initial bundle. It instructs the assistant to load analytics and monitoring after hydration. CX Codex +1 ★ 7,191repo stars bundle-conditional The bundle-conditional rule recommends loading large modules only when their feature is activated. It applies to lazy-loaded data and browser-only code in SSR builds. CX Codex +1 ★ 7,191repo stars react19-no-forwardref react19-no-forwardref is a Claude Code rule covering React 19 ref and context changes: pass ref as a prop and use use() instead of useContext(). It supports React 19 migrations. CX Codex +1 ★ 7,191repo stars

More in the catalog

Project sponsors

Companies that keep this analytics open