Created
December 15, 2023 20:35
-
-
Save jamesmurdza/ecc41e6dbcc08d27707427bfa4fa1f5b to your computer and use it in GitHub Desktop.
Emoji Hash
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
function stringToNumber(inputString) { | |
let hash = 0; | |
for (let i = 0; i < inputString.length; i++) { | |
const charCode = inputString.charCodeAt(i); | |
hash = (hash << 5) - hash + charCode; | |
} | |
hash = Math.abs(hash); | |
return hash; | |
} | |
function getEmoji(inputString) { | |
const base = 0x1F600; // Starting point of the emoji range in Unicode | |
const offset = stringToNumber(inputString) % 80; | |
const emojiCode = base + offset; | |
return String.fromCodePoint(emojiCode); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment