-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.js
More file actions
60 lines (49 loc) · 963 Bytes
/
Copy pathdictionary.js
File metadata and controls
60 lines (49 loc) · 963 Bytes
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function Dictionary() {
var items = {};
this.set = function (key, value) {
items[key] = value;
};
this.get = function (key) {
return this.has(key) ? items[key] : undefined;
}
this.delete = function (key){
if (this.has(key)) {
delete items[key];
return true;
}
return false;
};
this.has = function (key) {
// if (Object.keys(items).indexOf(key) != -1) {
// return true;
// }else{
// return false;
// }
return key in items;
};
this.values = function () {
let values = [];
for( let k in items) {
if (this.has(k)) {
values.push(items[k]);
}
}
return values;
}
this.clear = function() {
items = {};
};
this.size = function () {
return Object.keys(items).length;
};
this.keys = function() {
return Object.keys(items);
};
this.getItems = function() {
return items;
}
}
let dir = new Dictionary();
dir.set('name', 'Cyclone');
dir.set('partner','Joker');
console.log(dir.has('name'));;