Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
Is there anyway to make this code faster?

I have a code here that automatically tick a box when all three boxes are true, however this is taking forever to load as I have thousands of boxes in the sheet, is there any way to make this code quicker?

at the moment the code is making everything lag and unresponsive

function checkBox(j,k,l,m,result){ 
 
  var result = true;

  if ( j === true && k === true & l === true && m === true) {
    result = true;
  } else {
    result = false;
  }

  return result;

}

if the first four boxes are tick, then box number 6 will automatically tick, but it's taking forever to load

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Not sure what you are doing wrong, but this code took 46ms for 10,000 lines - a little longer to render on the screen.

function go(){

    //set up a test table with every 10th row with all boxes ticked
    let str="<table>";
    for (let i=0;i<10000;i++){
        str +="<tr>";
        for (let j=0;j<4;j++){
            str +="<td><input type='checkbox'></td>";
        }
        str +="<td> </td><td><input type='checkbox'</td>";
        str +="</tr>";
    }
    str +="</table>";

    container.innerHTML=str;


    //start here to compute the result column

    let start=(new Date()).getTime();
    let table=container.querySelector("table");
    let rows=table.querySelectorAll("tr");

    for (let i=0;i<rows.length;i++){
        let inputs=rows[i].querySelectorAll("input");
        if(i%10==0){
            for (let j=0;j<4;j++)inputs[j].checked=true;
        }
        else {
            for (let j = 0; j < 4; j++) {
                if (Math.random() < 0.5) inputs[j].checked = true;
            }
        }
        inputs[4].checked=inputs[0].checked && inputs[1].checked && inputs[2].checked && inputs[3].checked;
    }

    alert((new Date()).getTime()-start);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda