Created
April 19, 2017 23:14
-
-
Save soundyogi/0bd139c6fb805df61b1741c4550e07b6 to your computer and use it in GitHub Desktop.
hash string to int
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 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