0
How do I "limit the amount of values ordered by go below?
I tried to create an array with the Divs and change the display property.. but it does not take the order of the elements..
Much of this code was taken from a previous topic.
// Seleciona as divs que queremos ordenar
var divs = document.querySelectorAll('#res .alqb');
// Converte a NodeList de divs para array
var ordem = [].map.call(divs, function(element) {
return element;
});
// Ordena a array pelo atributo 'value'
ordem.sort(function(a,b) {
var ca = parseInt(a.getAttribute('value'), 10);
var cb = parseInt(b.getAttribute('value'), 10);
return cb - ca;
});
// Reinsere os filhos no pai, resultando na ordem desejada
var container = document.querySelector('#res');
for(var i=0; i<ordem.length; i++) {
container.appendChild(ordem[i]);
}
trocacorresp();
qtdjogo();
}
Hello Vitor, can you explain the question better? perhaps with an example of what you want to do?
– Sergio
The above code returns in order of size from the largest to the smallest some numbers that repeat more times in a given range would like to do as if it were a "filter" of the first 6.. that is to say the six highest values...
– Vitor Flávio
Forehead join
.slice(0, 6)
to look like this:ordem.sort(..etc..).slice(0, 6);
. That’s what you’re looking for?– Sergio