Skip to content

Instantly share code, notes, and snippets.

@nire0510
Created March 29, 2016 13:11
Show Gist options
  • Save nire0510/0c9869774a7d5beb7c6e to your computer and use it in GitHub Desktop.
Save nire0510/0c9869774a7d5beb7c6e to your computer and use it in GitHub Desktop.
Generates has based on method parameters
function generateHash() {
let intHash = 0,
strChar,
intLength,
strInput = [...arguments].join('');
if (strInput.length === 0) {
return intHash;
}
for (let i = 0, intLength = strInput.length; i < intLength; i++) {
strChar = strInput.charCodeAt(i);
intHash = ((intHash << 5) - intHash) + strChar;
intHash |= 0; // Convert to 32bit integer
}
return intHash;
}
// Sample:
generateHash(1, 'bla', 'foo', 920);
// => 383408311
generateHash(19817623);
// => 196639745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment