Last active
July 4, 2019 15:02
-
-
Save stvkoch/8f4a61d989e1cac51ce7d938e2840df6 to your computer and use it in GitHub Desktop.
generateHashFromObject
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 generateHashFromObject = (obj) => | |
Object.entries(obj).reduce((hash, [key, str])=> { | |
let result = hash; | |
if (!str || !key) return hash; | |
if (!str.charCodeAt && !isNaN(str)) { | |
result = (result * 33) ^ str; | |
} | |
if (!key.charCodeAt && !isNaN(key)) { | |
result = (result * 33) ^ key; | |
} | |
let i = str.length; | |
if (str.charCodeAt) | |
while (i) { | |
result = (result * 33) ^ str.charCodeAt(--i); | |
} | |
i = key.length; | |
if (key.charCodeAt) | |
while (i) { | |
result = (result * 33) ^ key.charCodeAt(--i); | |
} | |
return result >>> 0; | |
}, | |
5381, | |
).toString(32); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment