Created
June 13, 2017 13:03
-
-
Save larchanka/4147b1872b995815d059b1bf1a7ca32b to your computer and use it in GitHub Desktop.
contentHashGenerator generates a short number hash from the string
This file contains 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
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