mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-12-26 23:21:18 +08:00
Update hash table methods.
This commit is contained in:
parent
ecd8d22fc6
commit
5b3de38cca
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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');
|
||||||
|
Loading…
Reference in New Issue
Block a user