Created
May 8, 2018 06:47
-
-
Save lshaf/c4cded2864e78f54414cd1fd4d8f951f to your computer and use it in GitHub Desktop.
Converting numeric id to character id
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 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