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

102
Vistas
How to console log pairs in array

For example I have this string "()[]|}" and I want to compare each characters with eachother, but first I can't get the loop to work correctly. For the first log it works correctly, but after instead of going +1 it should go +2 I believe so it doesn't start from ). How do can I do this properly?

function isValid(s) {
    
  let temp = s.split("");

  for (let i = 0; i < s.length/2; i++) {
        console.log(temp[i], temp[i+1]);
  }
};

isValid("()[]|}");

I want to log this

( )
[ ]
| }

not

( )
) [
[ ]
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If the question is 'how do I increment by two instead of by 1', use i += 2 instead of i++ (since the increment operator only increments by 1)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Your code is correct but your for loop is slightly off:

for (let i = 0; i < s.length; i += 2) {

Loop while i is less than the length, but add 2 instead of 1.

function isValid(s) {
    
  let temp = s.split("");

  for (let i = 0; i < s.length; i += 2) {
        console.log(temp[i], temp[i+1]);
  }
};

isValid("()[]|}");

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