Considering an array of objects structured as follows:
[{
"202201": {
"WO": 900,
"WS": 0,
"SY": 0.915,
"LY": 0.98,
"CT": 75
},
"202202": {
"WO": 300,
"WS": 0,
"SY": 0.915,
"LY": 0.98,
"CT": 73
},
"202203": {
"WO": 350,
"WS": 0,
"SY": 0.915,
"LY": 0.98,
"CT": 68
},
"202204": {
"WO": 400,
"WS": 0,
"SY": 0.915,
"LY": 0.98,
"CT": 77
},
"202205": {
"WO": 300,
"WS": 0,
"SY": 0.915,
"LY": 0.98,
"CT": 67
},
"Product": "A",
"Facility": "a-Facility"
},
{
"202201": {
"WO": 6665,
"WS": 0,
"SY": 0.903,
"LY": 0.993,
"CT": 73
},
"202202": {
"WO": 5907,
"WS": 0,
"SY": 0.903,
"LY": 0.993,
"CT": 71
},
"202203": {
"WO": 5893,
"WS": 0,
"SY": 0.903,
"LY": 0.993,
"CT": 74
},
"202204": {
"WO": 5486,
"WS": 0,
"SY": 0.903,
"LY": 0.993,
"CT": 67
},
"202205": {
"WO": 5448,
"WS": 0,
"SY": 0.903,
"LY": 0.993,
"CT": 69
},
"Product": "B",
"Facility": "b-Facility"
}]
The objective is to determine the highest "CT" (cycle time) for all products at a manufacturing line encompassing all facilities. In this instance, the maximum CT value is 77.
A comparable and contemporary approach can be found here:
Math.max(...array.map(o => o.y))
referenced in this query regarding max value extraction from an object array, although it does not delve into numeric properties of each object within an array.
I believe there's a method to map not just the array of objects, but also the object attributes with a "CT" property (replacing "undefined" with 0) to identify the aforementioned maximum value of 77. Further exploration will ensue while awaiting assistance.
This is a typescript application, however, a javascript solution will suffice.
PROGRESS:
An advanced alternative to double for loops is desired, hence if you can present superior options, it would be greatly appreciated:
numbers = [];
data.forEach(d => {
numbers = numbers.concat(Object.keys(d).map(p => d[p].CT ? d[p].CT : 0));
})
maxCycle = Math.max(...numbers);
data.forEach(d => {
for (const w in d) {
maxCycle = maxCycle < d[w]['CT'] ? d[w]['CT'] : maxCycle;
}
});