From 085bb2973e89b8fe23d987c428a7793345c08634 Mon Sep 17 00:00:00 2001 From: tmichell13 Date: Mon, 8 May 2023 16:19:27 -0400 Subject: [PATCH] addressed issue 1033, changed while to if in LinkedList and add new before Array in HashTable constructor --- src/data-structures/hash-table/HashTable.js | 2 +- src/data-structures/linked-list/LinkedList.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data-structures/hash-table/HashTable.js b/src/data-structures/hash-table/HashTable.js index b8b523ea..33613125 100644 --- a/src/data-structures/hash-table/HashTable.js +++ b/src/data-structures/hash-table/HashTable.js @@ -12,7 +12,7 @@ export default class HashTable { */ constructor(hashTableSize = defaultHashTableSize) { // Create hash table of certain size and fill each bucket with empty linked list. - this.buckets = Array(hashTableSize).fill(null).map(() => new LinkedList()); + this.buckets = new Array(hashTableSize).fill(null).map(() => new LinkedList()); // Just to keep track of all actual keys in a fast way. this.keys = {}; diff --git a/src/data-structures/linked-list/LinkedList.js b/src/data-structures/linked-list/LinkedList.js index ba7d0e3e..79783525 100644 --- a/src/data-structures/linked-list/LinkedList.js +++ b/src/data-structures/linked-list/LinkedList.js @@ -101,7 +101,7 @@ export default class LinkedList { // If the head must be deleted then make next node that is different // from the head to be a new head. - while (this.head && this.compare.equal(this.head.value, value)) { + if (this.head && this.compare.equal(this.head.value, value)) { deletedNode = this.head; this.head = this.head.next; }