I have this JS Array ...
var arr = [{
"Event_code": "BW-087",
"Interest_area": "Information technology",
"Start_time": "9:00 AM",
"End_time": "3:00 PM",
"Session_type": "Experience",
"all_day_evt": true
}, {
"Event_code": "BW-161",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "9:00 AM",
"End_time": "3:00 PM",
"Session_type": "Experience",
"all_day_evt": true
}, {
"Event_code": "BW-114",
"Interest_area": "Nursing and midwifery",
"Start_time": "9:00 AM",
"End_time": "3:00 PM",
"Session_type": "Tour",
"all_day_evt": true
}, {
"Event_code": "BW-033",
"Interest_area": "",
"Start_time": "9:00 AM",
"End_time": "3:00 PM",
"Session_type": "General information session",
"all_day_evt": true
}, {
"Event_code": "BW-115",
"Interest_area": "Food, Nutrition and dietetics",
"Start_time": "9:30 AM",
"End_time": "3:00 PM",
"Session_type": "Tour",
"all_day_evt": true
}, {
"Event_code": "BW-060",
"Interest_area": "Sport",
"Start_time": "9:30 AM",
"End_time": "3:00 PM",
"Session_type": "Tour",
"all_day_evt": true
}, {
"Event_code": "BW-081",
"Interest_area": "Information technology",
"Start_time": "9:00 AM",
"End_time": "9:30 AM",
"Session_type": "Course information session",
"all_day_evt": false
}, {
"Event_code": "BW-170",
"Interest_area": "",
"Start_time": "9:30 AM",
"End_time": "10:30 AM",
"Session_type": "General information session",
"all_day_evt": false,
"clash": "This clashes with another session"
}, {
"Event_code": "BW-032",
"Interest_area": "",
"Start_time": "9:30 AM",
"End_time": "10:00 AM",
"Session_type": "General information session",
"all_day_evt": false
}, {
"Event_code": "BW-096",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "10:00 AM",
"End_time": "12:00 PM",
"Session_type": "Experience",
"all_day_evt": false
}, {
"Event_code": "BW-163",
"Interest_area": "Business",
"Start_time": "10:00 AM",
"End_time": "2:00 PM",
"Session_type": "Experience",
"all_day_evt": false,
"clash": "This clashes with another session"
}, {
"Event_code": "BW-048",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "12:00 PM",
"End_time": "12:30 PM",
"Session_type": "Experience",
"all_day_evt": false
}, {
"Event_code": "BW-128",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "12:00 PM",
"End_time": "12:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
}, {
"Event_code": "BW-018",
"Interest_area": "Sciences",
"Start_time": "12:30 PM",
"End_time": "2:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
}, {
"Event_code": "BW-013",
"Interest_area": "Sciences, Engineering, Information technology, Architecture and built environment, Environment",
"Start_time": "12:30 PM",
"End_time": "1:00 PM",
"Session_type": "Course information session",
"all_day_evt": false
}, {
"Event_code": "BW-039",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "1:00 PM",
"End_time": "1:30 PM",
"Session_type": "Experience",
"all_day_evt": false
}, {
"Event_code": "BW-162",
"Interest_area": "Education and teaching",
"Start_time": "1:00 PM",
"End_time": "1:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
}]
arr.sort((x,y) => y.all_day_evt- x.all_day_evt || ((new Date('1970/01/01 ' + x.Start_time)) - (new Date('1970/01/01 ' + y.Start_time))));
console.log(arr);
I am looking to do 3 operations on this array ...
- Group this array by "all_day_evt" key.
- Sort this array within the 'true' subgroup, and 'false' subgroup by 'Start_time'.
- Sort if there is a "clash" on 'start_time' ... with the "clashed event" showing up 2nd.
I am not sure how to implement the 3rd condition, any help is very appreciated. Thanks
Sample output shown below - highlighting how the clash events should line up. It should show up so that the event with "clash" key comes 2nd, not first.
For example, events "BW-013" & "BW-018" are clashing at start_time of 12:30 PM. So, 'BW-013' comes first, and then 'BW-018' shows up. Same goes with events 'BW-039' and 'BW-162' as shown in example output below.
[{
"Event_code": "BW-013",
"Interest_area": "Sciences, Engineering, Information technology, Architecture and built environment, Environment",
"Start_time": "12:30 PM",
"End_time": "1:00 PM",
"Session_type": "Course information session",
"all_day_evt": false
},
{
"Event_code": "BW-018",
"Interest_area": "Sciences",
"Start_time": "12:30 PM",
"End_time": "2:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
},
{
"Event_code": "BW-039",
"Interest_area": "Media, Communication and creative arts",
"Start_time": "1:00 PM",
"End_time": "1:30 PM",
"Session_type": "Experience",
"all_day_evt": false
}, {
"Event_code": "BW-162",
"Interest_area": "Education and teaching",
"Start_time": "1:00 PM",
"End_time": "1:30 PM",
"Session_type": "Tour",
"all_day_evt": false,
"clash": "This clashes with another session"
}
]
sort()logic you haven isn't actually doing anything. Can you give an example of the output you're expecting to achieve