Skip to content

Instantly share code, notes, and snippets.

@soundyogi
Created April 19, 2017 23:14
Show Gist options
  • Save soundyogi/0bd139c6fb805df61b1741c4550e07b6 to your computer and use it in GitHub Desktop.
Save soundyogi/0bd139c6fb805df61b1741c4550e07b6 to your computer and use it in GitHub Desktop.
hash string to int
function hashCode (str){
var hash = 0;
if (str.length == 0) return hash;
for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment