Skip to content

Instantly share code, notes, and snippets.

@dosjota
Last active February 19, 2018 20:58
Show Gist options
  • Save dosjota/86f8f65e8284d5dd9a1c to your computer and use it in GitHub Desktop.
Save dosjota/86f8f65e8284d5dd9a1c to your computer and use it in GitHub Desktop.
codigos MF
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