Created
December 2, 2014 20:11
-
-
Save dosjota/1cd9f582881d72879ffb to your computer and use it in GitHub Desktop.
Generar id único ejemplo: _idUnico(5,'_')
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 _idUnico = function(secuencia, separador) { | |
//valores por defecto | |
secuencia = typeof(secuencia) != 'undefined' ? secuencia : 1; | |
separador = typeof(separador) != 'undefined' ? separador : '-'; | |
var id = '', | |
a=1; | |
for (var i = 0; i < secuencia; i++) { | |
separador = ( secuencia=== a) ? '': separador; | |
id = id+Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)+separador; | |
a++; | |
} | |
return id | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment