If I have an array containing various items like the following:
[
["Core", "Mathematics", "Mathematics 20-4"],
["Core", "Mathematics", "Mathematics 30-1"],
["Other", "Fine Arts", "Art", "some art course"],
["Other", "Fine Arts", "Music", "some music course"],
["Other", "Forensics", "some forensics course"],
["French Immersion", "Core", "Mathématiques", "Mathématiques 30-1"]
]
The structure being "Department -> Subject -> Course".
I am looking to generate a dynamic Array (or Object) in the format below (or any other logical structure)...
{
subjects: [
{
title: "Mathematics", courses: [ "Mathematics 20-4", "Mathematics 30-1" ]
},
{
title: "Mathématiques", lang: "fr", courses: [ "Mathématiques 30-1" ]
}
],
other: {
subjects: [
{
title: "Forensics", courses: [ "some forensics course" ]
},
{
title: "Fine Arts", subjects: [
{
title: "Art", courses: [ "some art course" ]
},
{
title: "Music", courses: [ "some music course" ]
}
]
}
]
}
}
The "Other" department does not strictly adhere to the "Subject -> Course" hierarchy and can vary with "Subject -> Subject -> Course" and "Subject -> Course". Introducing a type attribute such as "course" or "subject" may be helpful, but maintaining a hierarchical structure is preferred.
I have been struggling to dynamically convert this into an Array or Object structure.