When working with AngularJS/Javascript, I have an array of objects that each contain a date. My goal is to order these objects by date and then add an attribute to the last object that has a specific datetime. If there are two objects with the same date, the attribute should be added to the one with the latest time. If there is only one object with a particular date, then the attribute should be added to that object.
For example:
input: var arr = [
{A: {"Date": "2017-08-14T15:15:00"} B:{}}
{A: {"Date": "2017-08-14T16:15:00"} B:{}} //<--- Add attribute to this object
]
output: var arr = [
{A: {"Date": "2017-08-14T15:15:00"} B:{}}
{A: {"Date": "2017-08-14T16:15:00"} B:{} C:{"NewAttribute": "true"}}
]
I am unsure how to approach programming this. Initially, I thought about using a for loop to compare all the objects, but I'm stuck on how to implement it.