Update hash table methods.

This commit is contained in:
Oleksii Trekhleb 2018-05-31 21:35:53 +03:00
parent ecd8d22fc6
commit 5b3de38cca
2 changed files with 3 additions and 2 deletions

View File

@ -78,7 +78,7 @@ export default class HashTable {
const bucketLinkedList = this.buckets[this.hash(key)]; const bucketLinkedList = this.buckets[this.hash(key)];
const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key }); const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key });
return node ? node.value.value : null; return node ? node.value.value : undefined;
} }
/** /**

View File

@ -43,12 +43,13 @@ describe('HashTable', () => {
expect(hashTable.get('a')).toBe('sky'); expect(hashTable.get('a')).toBe('sky');
expect(hashTable.get('d')).toBe('ocean'); expect(hashTable.get('d')).toBe('ocean');
expect(hashTable.get('x')).not.toBeDefined();
hashTable.delete('a'); hashTable.delete('a');
expect(hashTable.delete('not-existing')).toBeNull(); expect(hashTable.delete('not-existing')).toBeNull();
expect(hashTable.get('a')).toBeNull(); expect(hashTable.get('a')).not.toBeDefined();
expect(hashTable.get('d')).toBe('ocean'); expect(hashTable.get('d')).toBe('ocean');
hashTable.set('d', 'ocean-new'); hashTable.set('d', 'ocean-new');