From 5b3de38cca34e544e52e603369e7fe151c73e148 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Thu, 31 May 2018 21:35:53 +0300 Subject: [PATCH] Update hash table methods. --- src/data-structures/hash-table/HashTable.js | 2 +- src/data-structures/hash-table/__test__/HashTable.test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/data-structures/hash-table/HashTable.js b/src/data-structures/hash-table/HashTable.js index 785efff8..51575f98 100644 --- a/src/data-structures/hash-table/HashTable.js +++ b/src/data-structures/hash-table/HashTable.js @@ -78,7 +78,7 @@ export default class HashTable { const bucketLinkedList = this.buckets[this.hash(key)]; const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key }); - return node ? node.value.value : null; + return node ? node.value.value : undefined; } /** diff --git a/src/data-structures/hash-table/__test__/HashTable.test.js b/src/data-structures/hash-table/__test__/HashTable.test.js index 3c77769a..cc322150 100644 --- a/src/data-structures/hash-table/__test__/HashTable.test.js +++ b/src/data-structures/hash-table/__test__/HashTable.test.js @@ -43,12 +43,13 @@ describe('HashTable', () => { expect(hashTable.get('a')).toBe('sky'); expect(hashTable.get('d')).toBe('ocean'); + expect(hashTable.get('x')).not.toBeDefined(); hashTable.delete('a'); expect(hashTable.delete('not-existing')).toBeNull(); - expect(hashTable.get('a')).toBeNull(); + expect(hashTable.get('a')).not.toBeDefined(); expect(hashTable.get('d')).toBe('ocean'); hashTable.set('d', 'ocean-new');