I was given these two arrays of objects:1-
{
completed_on: "08/24/2021",
contractor: null,
created_on: "08/24/2021",
description: "Testing",
documents: [],
due_date: "08/05/2021",
equipment: 86877,
id: 1493,
name: "Testing for Demo", urgent: false
}
2-
{
action: "Complete",
contractor: null,
created_on: "08/26/2021",
date: "08/26/2021",
equipment: { label: "Mercruiser | 8.2 HO | 2A453486"},
hours: 0,
id: 56185,
invoice: null,
note: "Closed one time",
schedule: "One time task to close",
task: {
created_on: "2018-04-04",
description: "It is advisable to replace sensors every three years due to harsh environmental conditions encountered in marine applications.",
due_date: "2018-11-26",
due_hours: null,
equipment_id: 66036,
name: "Replace Sensors",
schedule_id: 4101,
task_id: 56185,
type: 1 updated_on: "2018-04-04"
}
}
And I would like to get an object like the one below. After processing both objects end up populating a new objects with these fields generated dynamically and conditionally depending on the data of the structure and data of the objects above.
{
taskStatus: String,
taskNote: String,
due_date: String,
taskTitle: String,
isRecurringTask: Boolean,
isOneTimeTask: Boolean,
isCorrectiveTask: false,
taskDescription: String,
taskId: Number,
taskHours: Number,
taskPrevNextDue: String,
taskCompletedOn: String,
taskCreatedOn: String,
taskEquipmentId: Number
}
I saw that Array,prototype.reduce
method might do the job but not sure how to use it since most documentation is pretty extensive explaining some other kind of scenarios.
Hopefully I’m explaining myself good enough so you guys can better understand to better help me,
Thanks in advance!