diff --git a/codes/javascript/chapter_hashing/simple_hash.js b/codes/javascript/chapter_hashing/simple_hash.js index 5c2a65409..4287515b3 100644 --- a/codes/javascript/chapter_hashing/simple_hash.js +++ b/codes/javascript/chapter_hashing/simple_hash.js @@ -31,7 +31,7 @@ function xorHash(key) { for (const c of key) { hash ^= c.charCodeAt(0); } - return hash & MODULUS; + return hash % MODULUS; } /* 旋转哈希 */ diff --git a/codes/typescript/chapter_hashing/simple_hash.ts b/codes/typescript/chapter_hashing/simple_hash.ts index 9d2be67c1..54c1fa283 100644 --- a/codes/typescript/chapter_hashing/simple_hash.ts +++ b/codes/typescript/chapter_hashing/simple_hash.ts @@ -31,7 +31,7 @@ function xorHash(key: string): number { for (const c of key) { hash ^= c.charCodeAt(0); } - return hash & MODULUS; + return hash % MODULUS; } /* 旋转哈希 */