function MyHashTable(){
var totalSize = 0;
var dataEntry = new Object();
this.addItem = function(key, value){
if(!isKeyPresent(key)){
totalSize++;
}
dataEntry[key] = value;
}
this.fetchValue = function(key){
return isKeyPresent(key) ? dataEntry[key] : null;
}
this.deleteItem = function(key){
if (isKeyPresent(key) && delete dataEntry[key]) {
totalSize--;
}
}
this.isKeyPresent = function(key){
return (key in dataEntry);
}
this.isValuePresent = function(value){
for(var prop in dataEntry){
if(dataEntry[prop] == value){
return true;
}
}
return false;
}
this.getAllValues = function(){
var values = new Array();
for(var prop in dataEntry){
values.push(dataEntry[prop]);
}
return values;
}
this.getAllKeys = function(){
var keys = new Array();
for(var prop in dataEntry){
keys.push(prop);
}
return keys;
}
this.getSize = function(){
return totalSize;
}
this.clearAll = function(){
totalSize = 0;
dataEntry = new Object();
}
}
var myHashTableExample = new MyHashTable();
myHashTableExample.addItem('name', 'John');
I am trying to create a custom hash table in JavaScript but when I run a test, I encounter an error message:
Uncaught ReferenceError: containsKey is not defined at MyHashTable.addItem (:8:3) at :64:10