Created
June 16, 2015 02:47
-
-
Save TheGU/4ca204936d9dba537b4c to your computer and use it in GitHub Desktop.
Create shorten URL like counting in base 62
This file contains hidden or 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
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