diff --git a/hasher.js b/hasher.js index b31a598..a038201 100644 --- a/hasher.js +++ b/hasher.js @@ -3,15 +3,15 @@ const crypto = require('crypto'); function Hasher() {} Hasher.prototype.hashToIndex = function (key, modulo) { + key = key || 0; let ch; let hash = key; - for (let i = 0; i < key.length; i++) { ch = key.charCodeAt(i); hash = ((hash << 5) - hash) + ch; hash = hash & hash; } - return Math.abs(hash || 0) % modulo; + return Math.abs(hash) % modulo; }; Hasher.prototype.hashToHex = function (key, algorithm) {