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

141
Visualizações
Plain Javascript: How to check if 1) array A has any elements of array B and 2) if array A has any elements array B doesn't have

The things I want to check:

  1. Does array A have any elements of array B?
  2. Does array A have any elements that array B doesn't have?

Scenario 1:

Array A = [1, 2]

Array B = [1, 2, 3, 4]

  1. Yes
  2. No

-> Give the answer true

Scenario 2:

Array A = [1, 2, 5]

Array B = [1, 2, 3, 4]

  1. Yes
  2. Yes

-> Give answer false

Scenario 3:

Array A = [5]

Array B = [1, 2, 3, 4]

  1. No
  2. Yes

-> Give answer false

I understand it may seem/be cocky to type basically a request for some code and expect someone to write it up, but I've spent 15 hours trying to either learn enough about arrays to do it myself, and also tried different solutions that were kind of close to what I asked on stackoverflow and tweaking them, but I just can't make a system that works by answering question 1) and 2) the way I want

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

0

  1. A.some((x) => B.includes(x))

  2. A.some((x) => !B.includes(x))

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