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

134
Vistas
How to check the JavaScript array objects are overlapping

I have an array of objects containing start and end range.

var ranges = [{
    start: 1,
    end: 5
}]

I want to push an object like this without overlapping with the previous start and end range

{
    start: 6,
    end: 10
}

How to check new object overlapping with the existing objects

Edit:

  {
        start: 50,
        end: 100
    },
{
        start: 11,
        end: 49
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Got the answer thanks everyone for your response.

let isValid = timeRanges.every(r => (r.begin != selected.begin && r.begin < selected.begin &&  selected.begin > r.end) && (r.end != selected.end && r.end < selected.begin &&  selected.end > r.end));
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try this :

const ranges = [{
  start: 1,
  end: 5
}];

const rangeObj = {
  start: 6,
  end: 10
};

function checkRangeOverlap(obj) {
  let res = ''
  ranges.forEach((obj) => {
    res = (obj.end > rangeObj.start) ? 'Overlaping': 'No Overlap';
  });
  return res;
}

console.log(checkRangeOverlap(rangeObj));

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