What is most efficient / elegant way to achieve sql-like filtering effect. I want to filter them and get only that objects which are max value in some group.
This is
Use map() and foreach() to get desired output
const arr=[{name:"bathroom",value:54,timeStamp:1562318089713},
{name:"bathroom",value:55,timeStamp:1562318090807},
{name:"bedroom",value:48,timeStamp:1562318092084},
{name:"bedroom",value:49,timeStamp:1562318092223},
{name:"room",value:41,timeStamp:1562318093467}];
let res = new Map();
arr.forEach((obj) => {
let values = res.get(obj.name);
if(!(values && values.value > obj.value)){
res.set(obj.name, obj)
}
})
console.log(res);
console.log([...res])