Created
February 13, 2022 21:59
-
-
Save chzager/ccb7a0c805087b415ac31a66c5e064b8 to your computer and use it in GitHub Desktop.
JavaScript string hash function
This file contains hidden or 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 stringHash (string) | |
{ | |
/* This is based on https://github.com/darkskyapp/string-hash | |
Since the basic code is public domain, this function is public domain as well. | |
*/ | |
let hash, i = string.length; | |
while (i) | |
{ | |
hash = (hash * 33) ^ string.charCodeAt(--i); | |
}; | |
return hash >>> 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment