I have an array of custom objects which is populated with user inputs. The array looks like this:
let array = [
{Course: "Design", Hours: "01:00:00", Week: "1"},
{Course: "Design", Hours: "01:00:00", Week: "3"},
{Course: "Design", Hours: "01:00:00", Week: "2"},
{Course: "Design", Hours: "01:00:00", Week: "1"},
{Course: "Design", Hours: "01:00:00", Week: "2"}
]
I need to modify this array so all hours from the same week will be calculated, and the values will be placed in the array according to the order of the weeks. My desired result would be like this:
let newArray = [
{Course: "Design", Hours: "02:00:00", Week: "1"},
{Course: "Design", Hours: "02:00:00", Week: "2"},
{Course: "Design", Hours: "01:00:00", Week: "3"},
]
So basically I need to sort and calculate the sum at the same time.