Skip to content

Instantly share code, notes, and snippets.

@jamesmurdza
Created December 15, 2023 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmurdza/ecc41e6dbcc08d27707427bfa4fa1f5b to your computer and use it in GitHub Desktop.
Save jamesmurdza/ecc41e6dbcc08d27707427bfa4fa1f5b to your computer and use it in GitHub Desktop.
Emoji Hash
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