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

194
Visualizações
How can I compare two arrays with different length but they share the same values?

For Example:

let array1 = [3, 1, 2, 5];
let array2 = [1, 2, 3];

How can I compare the both arrays to get my output a boolean value?

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

0

If you want to check if one array is a subset of another array then you could try something like this:

let array1 = [3, 1, 2, 5];
let array2 = [1, 2, 3];

let isSubset = (arr1,arr2) => arr1.every(x=> arr2.includes(x));

console.log('Is array1 a subset of array2?',isSubset(array1,array2));
console.log('Is array2 a subset of array1?',isSubset(array2,array1));

Here first console.log returns false because not all elements of array1 are present in array2.
But when we swap params inside isSubset function we now check if all of the elements of array2 are present in array1. In this case we're getting true state.

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