Skip to content

Instantly share code, notes, and snippets.

@larchanka
Created June 13, 2017 13:03
Show Gist options
  • Save larchanka/4147b1872b995815d059b1bf1a7ca32b to your computer and use it in GitHub Desktop.
Save larchanka/4147b1872b995815d059b1bf1a7ca32b to your computer and use it in GitHub Desktop.
contentHashGenerator generates a short number hash from the string
const contentHashGenerator = (str = '') => {
let hash = 0;
let i;
let chr;
if (str.length === 0) return hash;
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
// eslint-disable-next-line
hash = ((hash << 5) - hash) + chr;
// eslint-disable-next-line
hash |= 0;
}
return hash;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment