-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.js
46 lines (34 loc) · 1.19 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
43
44
45
46
// 45: Map.prototype.get() (solution)
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Map.prototype.get` returns the element from the map for a key', function(){
it('`get(key)` returns the value stored for this key', function() {
let map = new Map();
map.set('key', 'value');
const value = map.get('key');
assert.equal(value, 'value');
});
it('multiple calls still return the same value', function() {
let map = new Map();
map.set('value', 'value');
var value = map.get(map.get(map.get('value')));
assert.equal(value, 'value');
});
it('requires exactly the value as passed to `set()`', function() {
let map = new Map();
const obj = {};
map.set(obj, 'object is key');
assert.equal(map.get(obj), 'object is key');
});
it('leave out the key, and you get the value set for the key `undefined` (void 0)', function() {
let map = new Map();
map.set(void 0, 'yo');
const value = map.get();
assert.equal(value, 'yo');
});
it('returns undefined for an unknown key', function() {
let map = new Map();
map.set(void 0, 1);
const value = map.get('key');
assert.equal(value, void 0);
});
});