Created
August 14, 2014 09:09
-
-
Save kanakiyajay/c21e294757b71a9b4a9c to your computer and use it in GitHub Desktop.
Angular: UID function creator
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
var uid = ['0', '0', '0']; | |
function nextUid() { | |
var index = uid.length; | |
var digit; | |
while(index) { | |
index--; | |
digit = uid[index].charCodeAt(0); | |
if (digit == 57 /*'9'*/) { | |
uid[index] = 'A'; | |
return uid.join(''); | |
} | |
if (digit == 90 /*'Z'*/) { | |
uid[index] = '0'; | |
} else { | |
uid[index] = String.fromCharCode(digit + 1); | |
return uid.join(''); | |
} | |
} | |
uid.unshift('0'); | |
return uid.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment