I want to store a random
generated data that looks like 1-2-3-4-5-6
using a javascript array
.
Each data may contain only the -
character and 6 unique numbers from 1
to 49
.
I declared the array as: var a = new Array();
Each time a new data is being generated, I store it like: a[data] = 1;
where data
might be 2-36-33-21-9-41
and 1
represents the ratio;
If the data generated already exists, I must increment the ratio, like: a[data]++;
Why is the length
property not available?
I need to refresh the length
value on the page each time a new unique data has been generated, maybe at each 1 millisecond.
I can't parse a 1 million array that fast ... each time ...
this is how i insert or update:
if (variante_unice[s]) {
variante_unice[s]++;
}
else
{
variante_unice[s] = 1;
variante_unice_total++;
}
the code:
window.setInterval(
function() {
variante++;
$("#variante").text(variante);
for (j = 1; j <= 49; j++) {
$("#v" + j).attr("class", "");
}
for (j = 1; j <= 49; j++) {
extracted[j] = 0;
}
ind = 0;
s = '';
while (ind < 6) {
r = Math.floor((Math.random() * 49) + 1);
if (extracted[r] == 0) {
//this is where i generate the data
if (s === '') {
s = r;
}
else
{
s += '-' + r;
}
//console.log(r);
extracted[r] = 1;
frecvency[r]++;
$("#n" + r).attr("class", "green");
$("#v" + r).attr("class", "green");
ind++;
//console.log('i'+frecventa[r]);
frecventa[r]++;
//console.log('d'+frecventa[r]);
$("#f" + r).text(frecventa[r]);
}
}
//is the generated data new? if not, increment ratio
if (variante_unice[s]) {
variante_unice[s]++;
}
else
{
variante_unice[s] = 1;
variante_unice_total++;
}
//console.log(variante_unice);
//console.log(variante_unice[s]);
//console.log(variante_unice.length);
//console.log(s);
verifica_varianta();
//console.log(extracted);
//console.log(frecvency);
}
, 1);