namastey-hash-map
Brief Description:
A JavaScript package implementing a Hash Map data structure with various important methods for efficient key-value pair management.
Features
set(key, value):
Adds a key-value pair to the hash map. If the key already exists, 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 associated with the given key. Returns true
if the key was found and removed, otherwise false
.
has(key):
Checks if the hash map contains the specified key. Returns true
if the key exists, otherwise false
.
keys():
Returns an array of all keys in the hash map.
values():
Returns an array of all values in the hash map.
Installations
To install the package globally, run:
npm install -g namastey-hash-map
Examples
const HashMap = require('namastey-hash-map');
const map = new HashMap();
map.set('name', 'Sanjiv');
console.log(map.get('name'));
map.set('age', 25);
console.log(map.has('age'));
map.delete('name');
console.log(map.get('name'));
console.log(map.keys());
console.log(map.values());