Safe code for new Set()
may look like:
let items = [];
for (let item of set)
if (isBad(item))
items.push(item);
for (let item of items)
set.delete(item)
Can I simplify code to:
for (let item of set)
if (isBad(item))
set.delete(item);
Safe code for new Map()
may look like:
let keys = [];
for (let [key, val] of map)
if (isBadKey(key) || isBadValue(val))
keys.push(key);
for (let key of keys)
map.delete(key)
Can I simplify code to:
for (let [key, val] of map)
if (isBadKey(key) || isBadValue(val))
map.delete(key)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…