Issue
I have got an array of objects where different objects has time slot, if there are consecutive time slot then I want to merge it as one and keep other the same and later the final result has to be sort as well, for better understanding please look at the input and output I want.
Input:
const timeArray = [
{ timeValue: "10:00am-11:00am" },
{ timeValue: "11:00am-12:00pm" },
{ timeValue: "12:00pm-1:00pm" },
{ timeValue: "3:00pm-4:00pm" },
{ timeValue: "4:00pm-5:00pm" },
{ timeValue: "5:00pm-6:00pm" },
{ timeValue: "10:00pm-11:00pm" },
{ timeValue: "7:00pm-8:00pm" },
{ timeValue: "8:00pm-9:00pm" }
];
Output: I want
const new = [
{ timeValue: "10:00am-1:00pm" },
{ timeValue: "3:00pm-6:00pm" },
{ timeValue: "7:00pm-9:00pm" },
{ timeValue: "10:00pm-11:00pm" }
];
What I did I just aligned the consecutive time slot I have trying from hours I got no clue, Please help I will be very thankful
Solution
This is the link for answer you can merge different groups of time slots
https://codesandbox.io/s/diff-time-moment-forked-n65fl3? file=/src/index.js:0-2849
Answered By - Ali Raees
Answer Checked By - - Cary Denson (ReactFix Admin)