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

155
Vistas
How to calculate time overlapping in Javascript

I want o find overlapped time slot with small code. Lets there are time slots:

const slots = [
    {
    start_time: '10:30',
    end_time: '11:00'
  },
  {
    start_time: '11:30',
    end_time: '12:00'
  }
]

And I got the value from user as:

const inputStartTime = '10:50';
const inputEndTime = '11:20';

I think, there will be no overlapping if inputStartTime > slots.end_time and inputEndTime < slots.start_time. So, I want to set a variable such as const overlappedSlots = // and get the output of that variable as (console.log(overlappedSlots)):

[{
  start_time: "10:30",
  end_time: "11:00"
}]

But, I can't get this output by writing this function:

const inputStartTime = '10:50';
const inputEndTime = '11:20';

const slots = [
    {
    start_time: '10:30',
    end_time: '11:00'
  },
  {
    start_time: '11:30',
    end_time: '12:00'
  }
]

const overlappedSlots = slots.filter(slot => !slot.end_time < inputStartTime || !slot.start_time > inputEndTime);
console.log(overlappedSlots)

What I was doing wrong there?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The error is when you use ! without parenthesis

const inputStartTime = '10:50';
const inputEndTime = '11:20';

const slots = [{
    start_time: '10:30',
    end_time: '11:00',
  },
  {
    start_time: '11:30',
    end_time: '12:00',
  },
];

const overlappedSlots = slots.filter(
  (slot) => inputStartTime > slot.start_time || !(slot.start_time > inputEndTime));
console.log(overlappedSlots);

about 4 years ago · Juan Pablo Isaza Denunciar

0

the problem with your code remains with ! Try this :

const overlappedSlots = slots.filter(slot => !(slot.end_time < inputStartTime) || !(slot.start_time > inputEndTime));

    console.log("over"+overlappedSlots);
about 4 years ago · Juan Pablo Isaza Denunciar

0

use && instead of || this will give you the result you want
time start : 10:30 end time: 11:00

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