Skip to content

Instantly share code, notes, and snippets.

@swcho
Created April 25, 2017 04:46
Show Gist options
  • Save swcho/dafc222a18ff1842ce6ce6f01f100b96 to your computer and use it in GitHub Desktop.
Save swcho/dafc222a18ff1842ce6ce6f01f100b96 to your computer and use it in GitHub Desktop.
String To Unsigned Int Has
// 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