-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.js
42 lines (34 loc) · 1.25 KB
/
solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 62: Map - `has()` (solution)
// To do: make all tests pass, leave the assert lines unchanged!
describe('`map.has()` indicates whether an element with a key exists', function() {
it('finds nothing in an empty map', function() {
let map = new Map();
const hasKey = map.has(void 0);
assert.equal(hasKey, false);
});
it('finds an element by it`s key', function() {
let map = new Map([['key', 'VALUE']]);
const hasKey = map.has('key');
assert.equal(hasKey, true);
});
it('finds `undefined` as key too', function() {
let map = new Map([[void 0, 'not defined key']]);
const hasUndefinedAsKey = map.has(void 0);
assert.equal(hasUndefinedAsKey, true);
});
it('does not coerce keys', function() {
let map = new Map([[1, 'one']]);
const findsStringOne = false;
assert.equal(map.has('1'), findsStringOne);
});
it('after removal (using `map.delete(<key>)`) it doesnt find the element anymore', function() {
let map = new Map([[1, 'one']]);
map.delete(1);
assert.equal(map.has(1), false);
});
it('adding an item (using `map.set(key, value)`) later will make `has()` return true', function() {
let map = new Map();
map.set(void 0, 'value');
assert.equal(map.has(void 0), true);
});
});