Skip to content

Instantly share code, notes, and snippets.

@TheGU
Created June 16, 2015 02:47
Show Gist options
  • Save TheGU/4ca204936d9dba537b4c to your computer and use it in GitHub Desktop.
Save TheGU/4ca204936d9dba537b4c to your computer and use it in GitHub Desktop.
Create shorten URL like counting in base 62
var shortener = function(seq) {
var new_str = "";
var chars = "abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY1234567890";
while (seq > 0) {
var k = seq % chars.length;
if (k == 0) {
k = 62;
seq--;
}
seq = Math.floor(seq / chars.length);
new_str += chars[k - 1];
}
return new_str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment