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

157
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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