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

158
Visualizações
Check if any item in one range is present within another range javascript

I am currently writing something that requires checking if one range contains any items from another range

var lvlRange = [];

        for (var i = sLVL; i <= dLVL; i++) {
            lvlRange.push(i);
        } 

var methodRange = [];

        for (var i = skillIdentity.method1Start; i <= skillIdentity.method1End; i++) {
            methodRange.push(i);
        }

For example, if the lvlRange array has everything from 1-30, I need to check if the methodRange also has anything between 1 and 30 in it. Essentially checking if they have any overlapping numbers.

Something like (if lvlRange shares any numbers with methodRange) return true;

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

0

.filter() returns only true results of a callback. This callback uses .includes() which will compare each number of A to the numbers of B.

const A = [0,11,55,66,77,99,111];
const B = [44,55,88,111,333];

const matches = A.filter(n => B.includes(n));

console.log(matches);

about 4 years ago · Juan Pablo Isaza Relatório

0

You could check if there is any intersection in the 2 arrays:

function isIntersection(arr1, arr2) {
  const intersection = arr1.filter(x => arr2.includes(x))
  return (intersection.length > 0)
}

var lvlRange = [1, 2, 3, 4, 5, 6, 7];
var methodRange = [0, 4, 8, 9];

// This logs true because the item '4' is present in both arrays
console.log( isIntersection(lvlRange, methodRange) )

This is explained in depth here: https://stackoverflow.com/a/33034768/5334486

about 4 years ago · Juan Pablo Isaza Relatório

0

Assuming integers and that the range starts at sLVL and ends at dLVL, the test can be peformed with the some method as follows:

if (methodRange.some(n => n >= sLVL && n <= dLVL)) {
  console.log('methodRange does contain some values in the lvlrange');
}
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