Handling collisions between hash tables

Sometimes, different keys can have the same hash value. We will call it a collision since we will try to set different key-value pairs to the same position of the HashTable instance. For example, let's take a look at what we get in the output with the following code:

const hash = new HashTable(); 
hash.put('Ygritte', 'ygritte@email.com');hash.put('Jonathan', 'jonathan@email.com');hash.put('Jamie', 'jamie@email.com');hash.put('Jack', 'jack@email.com');hash.put('Jasmine', 'jasmine@email.com');hash.put('Jake', 'jake@email.com');hash.put('Nathan', 'nathan@email.com');hash.put('Athelstan', 'athelstan@email.com');hash.put('Sue', 'sue@email.com');hash.put('Aethelwulf', 'aethelwulf@email.com');hash.put('Sargeras', ...

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.