Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!