Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4472ecc

Browse files
Hash method
1 parent 7f94fbc commit 4472ecc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

‎hashTable.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@ function HashNode(key, value, next) {
99
this.next = next || null;
1010
}
1111

12-
let myHT = new HashTable(10);
13-
console.log(myHT);
12+
HashTable.prototype.hash = function(key) {
13+
let total = 0;
14+
for (let i = 0; i < key.length; i++) {
15+
total += key.charCodeAt(i);
16+
}
17+
let bucket = total % this.numBuckets;
18+
return bucket;
19+
}
20+
21+
let myHT = new HashTable(30);
22+
23+
console.log(myHT.hash('Becca'));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /