Skip to content

Instantly share code, notes, and snippets.

@Suppenhuhn79
Created February 13, 2022 21:59
Show Gist options
  • Save Suppenhuhn79/ccb7a0c805087b415ac31a66c5e064b8 to your computer and use it in GitHub Desktop.
Save Suppenhuhn79/ccb7a0c805087b415ac31a66c5e064b8 to your computer and use it in GitHub Desktop.
JavaScript string hash function
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