Skip to main content
rule CX Codex

js-min-max-loop — Claude Code rule: what it does, how to install

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.

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-min-max-loop.md
Open on GitHub

What js-min-max-loop does

This guideline prevents the assistant from calling .sort() solely to extract extreme values. Running a full sort for an earliest date or highest ID incurs O(n log n) cost where a simple pass suffices. The rule guides the agent to write a standard for loop with O(n) performance.

When retrieving both boundary elements at once, the code tracks min and max in one pass without cloning the array. Methods like Math.min(...items) are discouraged on large lists because spread operations fail when call stack limits are reached.

What it helps with

  • Replace full .sort() calls when looking for extreme elements
  • Find both minimum and maximum values in a single loop
  • Prevent call stack overflow errors caused by Math.min(...spread)

Example prompts for the agent

  • Write a helper to get the latest updated project from an array
  • Find the oldest and newest records in this list without sorting

How to install js-min-max-loop

Manually: put the files in place

.claude/rules/js-min-max-loop.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-min-max-loop

How to install js-min-max-loop in Claude Code?

Save the rule file to .claude/rules/js-min-max-loop.md inside your project root directory.

What does js-min-max-loop do?

It guides the assistant to search for extreme array values using an O(n) loop rather than running an O(n log n) array sort.

Why avoid Math.min(...array) for boundary values?

Spreading a very large array into function arguments can exceed JavaScript call stack limits and trigger runtime errors.

Similar IDE rules

All IDE rules for Code review and refactoring →

From the same set20

The whole set →
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 js-set-map-lookups 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. 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

More in the catalog

Project sponsors

Companies that keep this analytics open