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

117
Vistas
I need to check if first number of array equals to the last

I have an array

    const array = [[1, 2], [3, 3]]; arr.forEach(el => {  
      if (el[0] === el[1]) {return true}
    })
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

There is no point in return true in a forEach

I assume you mean this:

const testArr = arr => arr[0] === arr[arr.length-1]; // test first and last

const array = [[1, 2], [3, 3]]; 

const testResults = array.map(el => testArr(el)); // map the results
console.log(testResults)

// filter: 

const same = array.filter(el => testArr(el)); // FIND the array that has same first and last 

console.log(same.flat())

about 4 years ago · Juan Pablo Isaza Denunciar

0

You should should every function

const arr = [[1, 2], [3, 3]]; 
const b = arr.every(el => el[0] === el[1]);
console.log(b); // false
about 4 years ago · Juan Pablo Isaza Denunciar

0

This should get the desired result. Just change console.log(true) to whatever you would like to do if they equal each other. This will work on any length of array.

const array = [
  [1, 2],
  [3, 3],
];

array.forEach((el) => {
  if (el[0] === el[el.length - 1]) {
    console.log(true);
  }
});
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