Created
April 25, 2017 04:46
-
-
Save swcho/dafc222a18ff1842ce6ce6f01f100b96 to your computer and use it in GitHub Desktop.
String To Unsigned Int Has
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
// http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery | |
export function hashCode(str) { | |
let hash = 0, i, chr; | |
if (str.length === 0) return hash; | |
for (i = 0; i < str.length; i++) { | |
chr = str.charCodeAt(i); | |
hash = ((hash << 5) - hash) + chr; | |
hash |= 0; // Convert to 32bit integer | |
} | |
return (hash + 2147483647) + 1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment