Last active
February 19, 2018 20:58
-
-
Save dosjota/86f8f65e8284d5dd9a1c to your computer and use it in GitHub Desktop.
codigos MF
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 validaCodigo (nuevoCodigo) { | |
var codigosExistentes = ['codigo', 'codigoDOS']; | |
for(i=0;i< codigosExistentes.length;i++) { | |
if(nuevoCodigo == codigosExistentes[i]){ | |
valido = false; | |
console.log('codigo existe : ' + nuevoCodigo + ' ID: ' + i); | |
break; | |
}else{ | |
valido = true | |
} | |
} | |
return valido; | |
} | |
function generaCodigos (cantidad) { | |
var alfanumerico = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", | |
codigo = ''; | |
cantidad = typeof(cantidad) != 'undefined' ? cantidad : 8; | |
for (var i = 0; i < cantidad; i++) { | |
codigo = codigo + alfanumerico.charAt(Math.floor((Math.random() * alfanumerico.length) + 1)) | |
}; | |
return codigo; | |
} | |
var a = 0, | |
total = 10; | |
regCodigos = []; | |
do { | |
console.log(a); | |
var codigoNuevo = generaCodigos(); | |
if(validaCodigo( codigoNuevo ) ){ | |
a += 1; | |
regCodigos.push(codigoNuevo); | |
}else{ | |
console.log('no almacena'); | |
} | |
} while (a < total); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment