Install this skill
npx skills add vercel-labs/agent-skillsWorks across Claude Code, Cursor, Codex, Copilot & Antigravity
Chaining high-order array methods like map, filter, or reduce creates redundant traversals over the same dataset. Every time a functional method is called on an array, the engine iterates through all elements to produce a new result. When processing large arrays, these repeated passes increase CPU usage and memory pressure unnecessarily. This skill refactors multiple iterative passes into a single imperative loop structure. By capturing multiple outcomes within one traversal of the data, the code executes faster and reduces the garbage collection overhead. This pattern is particularly useful when handling large collections where performance bottlenecks occur during data transformation or segmentation tasks. It simplifies complex logic into a single point of entry, making the data processing flow transparent and efficient for resource-constrained environments.
When to Use This Skill
- •Categorizing user records based on multiple distinct role flags
- •Splitting a master list into separate arrays based on status types
- •Processing large API responses that require multiple validation checks
- •Extracting metadata while simultaneously filtering invalid entries
How to Invoke This Skill
Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:
- “Optimize my array iteration code
- “Combine these multiple filter calls into one
- “Refactor this map and filter chain for better performance
- “Make my data processing logic more efficient
- “How do I reduce multiple loops over an array?
What this skill does
- •Consolidates disparate filter operations into a single loop
- •Reduces total CPU cycles spent on array traversal
- •Minimizes intermediate array creation and memory allocation
- •Groups logical data segmentation tasks into one pass
- •Improves cache locality for large dataset processing
When not to use it
- ✕When arrays are small enough that the micro-optimization is negligible
- ✕When functional programming paradigms mandate keeping code immutable for readability
- ✕When logic for each task is complex enough to merit separate, testable functions
Example workflow
- Identify multiple array methods running on the same source
- Define empty storage containers for each desired output
- Replace the chain with a single for...of or traditional for loop
- Implement conditional logic inside the loop body to distribute items
- Verify the output arrays match the original functional implementation
Pitfalls & limitations
- !Increased code verbosity compared to declarative chains
- !Risk of mutating the loop incorrectly if not handled carefully
- !Loss of function chaining expressiveness
FAQ
How it compares
While generic prompts might suggest basic syntax fixes, this skill focuses on architectural performance by replacing chained declarations with single-pass imperative logic.
📄 Full skill instructions — original source: vercel-labs/agent-skills
Multiple
.filter() or .map() calls iterate the array multiple times. Combine into one loop.**Incorrect (3 iterations):**
const admins = users.filter(u => u.isAdmin)
const testers = users.filter(u => u.isTester)
const inactive = users.filter(u => !u.isActive)**Correct (1 iteration):**
const admins: User[] = []
const testers: User[] = []
const inactive: User[] = []
for (const user of users) {
if (user.isAdmin) admins.push(user)
if (user.isTester) testers.push(user)
if (!user.isActive) inactive.push(user)
}How to Use This Skill Unit
Option A: Project-Specific (Recommended)
- Click "Download" above
- In your project, create the directory:
.agent/skills/js-combine-iterations/ - Save the file as
SKILL.md - The agent will automatically discover the skill based on its description.
Option B: Global Installation (All Agents)
Save the file to these locations to make it available across all projects:
- Claude Code:
~/.claude/skills/vercel-labs/agent-skills/js-combine-iterations/SKILL.md - Cursor:
~/.cursor/skills/vercel-labs/agent-skills/js-combine-iterations/SKILL.md - Antigravity:
~/.gemini/antigravity/skills/vercel-labs/agent-skills/js-combine-iterations/SKILL.md
🚀 Install with CLI:npx skills add vercel-labs/agent-skills