首页/ AI 技能 / @skilllib/skill-2117939930272410567
Skill站外收录 @skilllib/skill-2117939930272410567

js-set-map-lookups

通过将数组转换为 Set 或 Map 结构,显著提升重复成员检测的执行效率,避免每次检查都进行线性遍历,适用于需高频判断元素是否存在于集合中的场景。

0.0 (0) 18 次安装 原作者 编程导航
收录于 2026-01-22
数据库 AI 技能

Skills.MD

## Use Set/Map for O(1) Lookups Convert arrays to Set/Map for repeated membership checks. **Incorrect (O(n) per check):** ```typescript const allowedIds = ['a', 'b', 'c', ...] items.filter(item => allowedIds.includes(item.id)) ``` **Correct (O(1) per check):** ```typescript const allowedIds = new Set(['a', 'b', 'c', ...]) items.filter(item => allowedIds.has(item.id)) ```

评论 0

还没有评论,来抢沙发。