Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check for overlapping time javascript

const arr = [
   { start: '01:00', end: '04:00' },
   { start: '05:00', end: '08:00' },
   { start: '07:00', end: '11:00' },
   { start: '09:30', end: '18:00' },
];
const overlapping = (a, b) => {
   const getMinutes = s => {
      const p = s.split(':').map(Number);
      return p[0] * 60 + p[1];
   };
   return getMinutes(a.end) > getMinutes(b.start) && getMinutes(b.end) > getMinutes(a.start);
};
const isOverlapping = (arr) => {
   let i, j;
   for (i = 0; i < arr.length - 1; i++) {
       for (j = i + 1; j < arr.length; j++) {
         if (overlapping(arr[i], arr[j])) {
            return true;
         }
      };
   };
   return false;
};
console.log(isOverlapping(arr));
Comment

PREVIOUS NEXT
Code Example
Javascript :: stringToCapital.js 
Javascript :: PostManDocs 
Javascript :: NextJs + Material UI, manually refreshing causes 
Javascript :: wp include js 
Javascript :: next.js api typescript 
Javascript :: var maxNum = function(arr) {}; 
Javascript :: wait untill 2 
Javascript :: &quot in json 
Javascript :: backbone view initialize 
Javascript :: Different Pages For Different Routes In Backbone 
Javascript :: file path to blob javascript 
Javascript :: discord.js profile picture 
Javascript :: Backbone Collection Example 
Javascript :: update excel file in react js using sheetjs 
Javascript :: how to scroll element in javascript 
Javascript :: javascript declare multiple variables on one line 
Javascript :: how to generate random ip address in javascript 
Javascript :: moment duration 
Javascript :: how to upload file in node js 
Javascript :: static in class javascript 
Javascript :: ajax post request 
Javascript :: client position js 
Javascript :: Jenkins parse json keep order 
Javascript :: java script layout engine error 
Javascript :: javascript Passing Parameter as Default Values 
Javascript :: Create JavaScript Generators 
Javascript :: alphanumeric without space regex 
Javascript :: How to add pop-up confirmation in angular typescript. 
Javascript :: set angle in phaser 
Javascript :: phaser animation from png sequence 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =