# js-combine-iterations

js-combine-iterations tells the Claude agent to replace several filter or map passes over the same array with one loop that fills the results as it goes.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 1064 repo stars
- Author: jarrodwatts
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/jarrodwatts/claude-code-config/tree/HEAD/skills/vercel-react-best-practices/rules/js-combine-iterations.md
- Updated: 2026-01-21
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/js-combine-iterations

## What it does

A Claude rule about array passes. When `filter` or `map` calls run over the same array one after another, the agent should fold them into a single `for...of` loop that pushes matches into each result array. The rule's own example collapses three walks over `users` into one, filling the admin, tester and inactive lists on the same pass.

The file is plain markdown: a title, a few tags and a wrong/right pair written in TypeScript, where the correct version declares typed arrays and appends to them under a condition. It nudges the model rather than gating a build, so whether it takes effect depends on the agent reading it.

Impact is marked LOW-MEDIUM, and that reads right. One extra pass is rarely the bottleneck, and a single loop is harder to scan than a chain of `filter` calls. The rule trades brevity for speed, so it earns its place where the code runs constantly and is a matter of taste everywhere else.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/rules/js-combine-iterations.md` — The paths frontmatter field limits the files

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### Cursor

**Manually: put the files in place**
- File: `.cursor/rules/js-combine-iterations.mdc` — Frontmatter: description, globs, alwaysApply

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/js-combine-iterations.instructions.md` — The applyTo field sets which files it applies to

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/js-combine-iterations.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/js-combine-iterations.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/jarrodwatts/claude-code-config/tree/HEAD/skills/vercel-react-best-practices/rules/js-combine-iterations.md

## When to use it
- fold three array passes into one loop
- cut repeated `filter` calls on a hot path
- fill several result arrays during a single walk
- keep array handling consistent across a TypeScript codebase
- catch code that walks the same array more than once

## Example prompts
- Rewrite these three `filter` calls over `users` as one loop, following the `js-combine-iterations` rule.
- Check `users.ts` and merge any repeated passes over the same array.
- Collect admins, testers and inactive users in one pass.

## Similar
- [js-length-check-first](https://affpapa.org/en/nevibecode/rules/js-length-check-first.md) — rule · ★ 7191 repo stars
- [frontend-js-best-practices](https://affpapa.org/en/nevibecode/skills/frontend-js-best-practices.md) — skill · 341 installs
- [coding-standards](https://affpapa.org/en/nevibecode/skills/coding-standards.md) — skill · 7900 installs
- [js-performance-patterns](https://affpapa.org/en/nevibecode/skills/js-performance-patterns.md) — skill · 716 installs
- [dry-refactoring](https://affpapa.org/en/nevibecode/skills/dry-refactoring.md) — skill · 4100 installs
- [command-pattern](https://affpapa.org/en/nevibecode/skills/command-pattern.md) — skill · 668 installs

From the same set: [jarrodwatts/claude-code-config](https://affpapa.org/en/nevibecode/by/jarrodwatts/claude-code-config.md) — 20 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
