Skip to content

Instantly share code, notes, and snippets.

@lshaf
Created May 8, 2018 06:47
Show Gist options
  • Save lshaf/c4cded2864e78f54414cd1fd4d8f951f to your computer and use it in GitHub Desktop.
Save lshaf/c4cded2864e78f54414cd1fd4d8f951f to your computer and use it in GitHub Desktop.
Converting numeric id to character id
function idToChar(id) {
const alpha = "1234567890abcdefghijklmnopqrstuvwxyz-_";
var tempId = id;
var shortCode = "";
while (tempId > 0) {
var mod = tempId % alpha.length;
tempId = Math.floor(tempId / alpha.length);
shortCode = `${alpha.charAt(mod)}${shortCode}`;
}
return shortCode;
}
console.log(idToChar(1238038))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment