We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2816a1e commit bff5589Copy full SHA for bff5589
hashTable.js
@@ -21,9 +21,16 @@ HashTable.prototype.hash = function(key) {
21
HashTable.prototype.insert = function(key, value) {
22
let index = this.hash(key);
23
if (!this.buckets[index]) this.buckets[index] = new HashNode(key, value);
24
+ else if (this.buckets[index].key === key) {
25
+ this.buckets[index].value = value;
26
+ }
27
else {
28
let currentNode = this.buckets[index];
29
while (currentNode.next) {
30
+ if (currentNode.next.key === key) {
31
+ currentNode.next.value = value;
32
+ return;
33
34
currentNode = currentNode.next;
35
}
36
currentNode.next = new HashNode(key, value);
@@ -35,5 +42,8 @@ let myHT = new HashTable(30);
42
myHT.insert('Dean', 'dean@gmail.com');
43
myHT.insert('Megan', 'megan@gmail.com');
37
44
myHT.insert('Dane', 'dane@yahoo.com');
45
+myHT.insert('Dean', 'deanmachine@gmail.com');
46
+myHT.insert('Megan', 'megansmith@gmail.com');
47
+myHT.insert('Dane', 'dane1010@outlook.com');
38
48
39
49
console.log(myHT.buckets);
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments