isc30 / linq-collections

Strongly typed Linq and Collections implementation for Javascript and TypeScript (ECMAScript 5)
https://www.npmjs.com/package/linq-collections
MIT License
119 stars 12 forks source link

How to group by multiple keys and select those keys? #49

Open mcoblefias opened 3 years ago

mcoblefias commented 3 years ago

Doing a single key looks straight-forward.

var list = new List(myObjectArray)
  var result = list
    .groupBy(p => p.page)
    .select(g => ({
      page: g.key,
      count: g.value.count(),
    }))
    .toArray()

But how do I do multiple keys?

var list = new List(myObjectArray)
  var result = list
    .groupBy(p => ({ page: p.page, date: moment(p.dateTime).format('YYYY-MM-DD')}))
    .select(g => ({
      page: g.key.page, <-- ???
      date: g.key.date, <-- ???
      count: g.value.count(),
    }))
    .toArray()