namastey-hash-table
A simple and efficient JavaScript implementation of a Hash Table with various important methods.
Features
set(key, value)
: Adds a key-value pair to the hash table. If the key already exists, it updates the value.get(key)
: Retrieves the value associated with the given key. Returns undefined
if the key does not exist.delete(key)
: Removes the key-value pair from the hash table. Returns true
if the pair was removed, false
otherwise.has(key)
: Checks if the key exists in the hash table. Returns true
if the key exists, false
otherwise.keys()
: Returns an array of all the keys in the hash table.values()
: Returns an array of all the values in the hash table.
Installation
To install the package globally, run:
npm install -g .
Examples
const HashTable = require('namastey-hash-table');
const hashTable = new HashTable();
hashTable.set('name', 'Alice');
console.log(hashTable.get('name'));
hashTable.set('age', 25);
console.log(hashTable.keys());
console.log(hashTable.values());
hashTable.delete('age');
console.log(hashTable.has('age'));