- docs/agent/external: Vercel react-best-practices and composition-patterns (MIT), Addy Osmani accessibility (MIT), Anthropic frontend-design (Apache-2.0), official Payload skill at v3.92.1 (MIT) — text only, each with its licence, SOURCE.md (repo, commit) and an override note in front of the SKILL.md (ipal-kit first, Payload fetching over swr, DESIGN.md tokens, Payload 3 not 4); manifest.json with sha256 per file - scripts/vendor-external-skills.mjs (maintainer, not shipped): fetches by full commit SHA only, rejects non-text or executable files, regenerates the manifest; --check verifies it - ipal-skills --external [names]: copies ext-* after checking every file against the manifest, downloads nothing, never touches ext-* folders without ipal-kit's SOURCE.md, removes only retired ones it installed; an unknown name stops the run before anything is copied - AGENT.md §14, ipal-setup stage 2 (optional step), README: usage, overrides, how to update the pins - test/externalSkills.test.ts: pins are SHAs, no branch fetch, checksums, text only, licences, override note, installer leaves other folders alone Co-Authored-By: Claude Opus 5.5 <[email protected]>
38 lines
837 B
Markdown
38 lines
837 B
Markdown
---
|
||
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.
|