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

260
Vistas
how to check if an array contains the elements from a sub array

i want to check i an array contains the elements of any sub array, i.e. array1 = [10,11,12] array 2 = [[10, 11],[20, 21],[30, 31],[40, 41]];

array1 will be checked in series by each of array2's sub arrays and if the sub array elements are also in the array1 then to return true.

i've tried thing like:

      array2.some((arr) => {
        return arr.every((square) => {
          return array1.includes(square);
        });
      });

or

    for (let elem of array2) {
        if (elem.every((x) => array1.includes(x))) {
          return false;
        } else {
          return true;
        }
      }

any advice would be helpfull. thank you

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

0

You need to iterate the sub array as well for the sequence.

const
    array1 = [10, 11, 12],
    array2 = [[10, 11], [20, 21], [30, 31], [40, 41]],
    result = array2.some(a => {
        for (let i = 0, l = array1.length - 1; i < l; i++) {
            if (a.every((v, j) => v === array1[i + j])) return true;
        }
        return false;        
    });

console.log(result);

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