1.0.0 • Published 10 months ago

namastey-hash-table v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

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')); // Output: Alice

hashTable.set('age', 25);
console.log(hashTable.keys()); // Output: ['name', 'age']
console.log(hashTable.values()); // Output: ['Alice', 25]

hashTable.delete('age');
console.log(hashTable.has('age')); // Output: false