-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary.js
64 lines (62 loc) · 1.44 KB
/
dictionary.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function Dictionary()
{
this.datastore = [];
this.addKeyValuePair = function(key,value)
{
if(key && value)
{
this.datastore.push({Key: key, Value: value});
}
return this.datastore;
};
this.removeKeyValuePair = function(key)
{
for(var i = 0; i < this.datastore.length; i++)
{
if(this.datastore[i].Key === key)
{
this.datastore.splice(i,1);
return this.datastore;
}
}
return this.datastore;
};
this.removeKeyValuePairDuplicates = function(key)
{
for( i = 0; i < this.datastore.length; i++)
{
if(this.datastore[i].Key === key)
{
x.push(i);
}
}
if (x.length > 1)
{
for( q = 0; q < (x.length - 1); q++)
{
this.datastore.splice(x[q],1);
}
}
return this.datastore;
};
this.findKeyValuePair = function(key)
{
for(var i = 0; i < this.datastore.length; i++)
{
if(this.datastore[i].Key === key)
{
return this.datastore[i].Value;
}
}
return 0;
};
this.length = function()
{
return this.datastore.length;
}
this.data = function()
{
return this.datastore;
}
}
module.exports = {Dictionary: Dictionary};