Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
Creating a special characters table without any headers

I have 128 special characters in an array. I'm trying to create a special character table without any headers that is 16 cells long and has 8 rows and I'm having trouble with the logic of the loops I'm creating. I've removed the part that are creating the table as that isn't relevant.

var rowCount = 8;

// For each Row
for (var r = 0; r < rowCount; r++) {
  for (var c = (0 + (r * 8)); c < (r * 8) + 16; c++) {
    console.log(c);
  }
}

So for each row, I'm trying to loop through 16 items of the 128 char array. The first loop I have, c prints out 0-15 as I'm expecting but when r enters its second iteration, c begins printing from 8-23, which is not what I want. I'm trying to get it to print what's following the previous iteration so 16-32, and then the third iteration 33-49 and so forth.

Can anyone explain to me what I'm doing wrong and how to correct my logic please?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of doing any of the complicated math in the nested loop declaration for the columns, keep that part simple 0-15 and do the math after. Where the for loop begins and ends ultimately doesn't matter because there are still always the same number rows and columns (since you've statically declared them).

i.e., you're trying to accomplish this on the inner loop iterations:

  • for(var c = 0; c < 16; c++){}
  • for(var c = 16; c < 32; c++){}
  • for(far c = 32; c < 48; c++){}

The actual number that the for loop begins and ends at is ultimately arbitrary, what matters is that you are able to calculate the number of times it should iterate... in this case 16 times for the columns. So 0-16 is all you need.

var rowCount = 8;
// For each Row
for(var r = 0; r < rowCount; r++){
    // opening <tr>
    for(var c = 0; c < 16; c++){
        console.log( (r * 16) + c );
        console.log("r" + r + "c" + c);
        // do <td> stuff
    }
    // closing </tr>
}

Note: Snippet cuts off some of the earlier console log so you don't see the beginning so here is a fiddle. https://jsfiddle.net/u7fLdt2w/

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda