javascript filter array by groups of highest

Solutions on MaxInterview for javascript filter array by groups of highest by the best coders in the world

showing results for - "javascript filter array by groups of highest"
Constance
09 Feb 2018
1const 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}]
2
3const result = Object.values(arr.reduce((r, o) => {
4  r[o.name] = r[o.name] && r[o.name].value > o.value ? r[o.name] : o
5
6  return r
7}, {}))
8
9console.log(result)