Basic information
About js-set-map-lookups
Use Set and Map for O(1) membership lookups instead of array.includes(). Apply when checking membership repeatedly or performing frequent lookups against a collection.
js-set-map-lookups is an agent skill listed in the AddMCP.net directory, published by TheOrcDev. Runtime: TypeScript. License: MIT. The repository has 2,061 GitHub stars. Source code is hosted on github.com. Related topics: 8-bit, components, retro, shadcn, ui.
Overview
What is js-set-map-lookups?
name: js-set-map-lookups description: Use Set and Map for O(1) membership lookups instead of array.includes(). Apply when checking membership repeatedly or performing frequent lookups against a collection.
Use Set/Map for O(1) Lookups
Convert arrays to Set/Map for repeated membership checks.
Incorrect (O(n) per check):
const allowedIds = ['a', 'b', 'c', ...]
items.filter(item => allowedIds.includes(item.id))
Correct (O(1) per check):
const allowedIds = new Set(['a', 'b', 'c', ...])
items.filter(item => allowedIds.has(item.id))
Comments
No comments yet
Be the first to share feedback about this listing. Sign in to leave a comment.
Sign In