I believe what you're looking for can be done with a reducer and findIndex. If find index fails to match the device type it will return -1, we know that we don't have that type yet so it gets pushed into the aggregation.
LastReadingOfEach(measurements){
const devicesList = measurements.reduce((agg, device) => {
if (agg.findIndex(x => x.type === device.type) === -1) {
agg.push(device)
}
return agg
}, [])
console.log("devicesList : ", devicesList)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…