map.has()
indicates whether an element with a key exists
finds nothing in an empty map
let map = new Map();
const hasKey = map.hazz(void 0);
assert.equal(hasKey, false);
finds an element by it`s key
let map = new Map([['key', 'VALUE']]);
const hasKey = map.has();
assert.equal(hasKey, true);
finds undefined
as key too
let map = new Map([[void 0, 'not defined key']]);
const hasUndefinedAsKey = map;
assert.equal(hasUndefinedAsKey, true);
does not coerce keys
let map = new Map([[1, 'one']]);
const findsStringOne = true;
assert.equal(map.has('1'), findsStringOne);
after removal (using map.delete(<key>)
) it doesnt find the element anymore
let map = new Map([[1, 'one']]);
assert.equal(map.has(1), false);
adding an item (using map.set(key, value)
) later will make has()
return true
let map = new Map();
assert.equal(map.has(void 0), true);
Links
video
A video (15min) documenting how this kata was created.