Transform to filter groups of results?


Can I use transform (or anything else) to filter a group of results? I have rows of group-names and a number, for example:
Cakes 1
Cakes 2
Cakes 3
Soda 1
Soda 2

I want to see only the latest number available so - Cakes 3, Soda 2...

How might I go about it not within my sql code?

yep, there's a bunch of way you could go about doing that - it will depend on what your data structure is like so I've made a guess at what that could be:

var objects = [
  {name: 'a', count: 4 },
  {name: 'a', count: 2 },
  {name: 'a', count: 3 },
  {name: 'b', count: 3 },
  {name: 'b', count: 5 }
// find the max count of each name for each object in array 'objects' using reduce
return objects.reduce((agg, row) => {
  // if the count of the current row name is less than the highest value we've seen, ignore it - otherwise capture it
  agg[] = (row.count < agg[] ? agg[] : row.count);
  return agg;
}, {});

// =>
// a:4
// b:5

There's probably a neater way to do it with a Max function in a loop too

nb: I've assumed you wanted the largest value of each group, not sure if that's what "latest" meant?