Created
March 29, 2016 13:11
-
-
Save nire0510/0c9869774a7d5beb7c6e to your computer and use it in GitHub Desktop.
Generates has based on method parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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