Sunday, May 17, 2015

Write a Program to Implement HashTable in Java Script

<!DOCTYPE html>
<html>
<body>
<script>

function HashTable() {
var hashTableItems = {};
this.setItem = function(key, value) {
hashTableItems[key] = value;
}
this.getItem = function(key) {
return hashTableItems[key];
}
}

var hashTable = new HashTable();
hashTable.setItem('name', 'Ranga Reddy');
console.log(hashTable.getItem('name'));

var hashTable1 = new HashTable();
hashTable1.setItem('age', '27');
console.log(hashTable1.getItem('age'));
</script>
</body>
</html>

0 comments: