mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
* chore(ai-workflow): track repo-managed review tooling * fix(ai-workflow): remove repo-specific path assumptions Make shared workflow hooks and APK testing guidance resolve paths from the repo and contributor environment so the tooling works for all contributors, not just one machine.
33 lines
753 B
Markdown
33 lines
753 B
Markdown
---
|
|
title: Combine Multiple Array Iterations
|
|
impact: LOW-MEDIUM
|
|
impactDescription: reduces iterations
|
|
tags: javascript, arrays, loops, performance
|
|
---
|
|
|
|
## Combine Multiple Array Iterations
|
|
|
|
Multiple `.filter()` or `.map()` calls iterate the array multiple times. Combine into one loop.
|
|
|
|
**Incorrect (3 iterations):**
|
|
|
|
```typescript
|
|
const admins = users.filter(u => u.isAdmin)
|
|
const testers = users.filter(u => u.isTester)
|
|
const inactive = users.filter(u => !u.isActive)
|
|
```
|
|
|
|
**Correct (1 iteration):**
|
|
|
|
```typescript
|
|
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)
|
|
}
|
|
```
|