Context: I want to make a timetable planner that checks for time clashes. Any help is greatly appreciated.
Specific Problem: Can't figure out how to split my array of objects into multiple arrays with certain key repeated.
My data set:
let myCourses = [
{
course: "ee3001",
slots: [
{
day: "monday",
time: "0900-1100",
},
{
day: "tuesday",
time: "0930-1100",
},
{
day: "wednesday",
time: "1330-1530",
},
],
},
{
course: "ee3002",
slots: [
{
day: "monday",
time: "0900-1100",
},
{
day: "thursday",
time: "0930-1130",
},
],
},
{
course: "ee3003",
slots: [
{
day: "tuesday",
time: "0930-1100",
},
{
day: "wednesday",
time: "1330-1530",
},
{
day: "thursday",
time: "0930-1130",
},
],
},
];
Arrays I want to split it into:
let newarray = [
{
course: "ee3001",
slot: {
day: "monday",
time: "0900-1100",
},
},
{
course: "ee3001",
slot: {
day: "monday",
time: "1300-1400",
},
},
...
...
];
let newArray2 = //containing info on ee3002
let newArray3 = //containing info on ee3003
**Note:**Dataset is to be populated, ie. users are able to add more courses and timings.
- The reason for doing this is so that I can make use of Cartesian Product of arrays to find all combinations.
- Then I can check whether there is any time clash in a given combination.
- Is there a better way to solve this problem?