michael@0: // A map iterator can cope with removing the current entry. michael@0: michael@0: function test(pairs) { michael@0: print(uneval(pairs)); michael@0: var map = Map(pairs); michael@0: michael@0: var all_keys = ''; michael@0: var false_keys = ''; michael@0: for (let [k, v] of map) { michael@0: all_keys += k; michael@0: if (!v) michael@0: false_keys += k; michael@0: } michael@0: michael@0: var log = ''; michael@0: for (let [k, remove] of map) { michael@0: log += k; michael@0: if (remove) michael@0: map.delete(k); michael@0: } michael@0: assertEq(log, all_keys); michael@0: michael@0: var remaining_keys = [k for ([k] of map)].join(''); michael@0: assertEq(remaining_keys, false_keys); michael@0: } michael@0: michael@0: // removing the only entry michael@0: test([['a', true]]); michael@0: michael@0: // removing the first entry michael@0: test([['a', true], ['b', false], ['c', false]]); michael@0: michael@0: // removing a middle entry michael@0: test([['a', false], ['b', true], ['c', false]]); michael@0: michael@0: // removing the last entry michael@0: test([['a', false], ['b', false], ['c', true]]); michael@0: michael@0: // removing all entries michael@0: test([['a', true], ['b', true], ['c', true]]);