-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.js
More file actions
41 lines (35 loc) · 789 Bytes
/
Copy pathDictionary.js
File metadata and controls
41 lines (35 loc) · 789 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
function Dictionary() {
this.add = add;
this.datastore = new Array();
this.find = find;
this.remove = remove;
this.showAll = showAll;
this.count = count;
this.clear = clear;
}
function add(key, value) {
this.datastore[key] = value;
}
function find(key) {
return this.datastore[key];
}
function remove(key) {
delete this.datastore[key];
}
function showAll() {
for each (var key in Object.keys(this.datastore).sort()) {
print(key + " -> " + this.datastore[key]);
}
}
function count() {
var n = 0;
for each (var key in Object.keys(this.datastore)) {
++n;
}
return n;
}
function clear() {
for each (var key in Object.keys(this.datastore)) {
delete this.datastore[key];
}
}