Skip to content

Instantly share code, notes, and snippets.

@tuananh
Created June 25, 2019 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuananh/8f9bfd3719d8e6b45fd11625b3756454 to your computer and use it in GitHub Desktop.
Save tuananh/8f9bfd3719d8e6b45fd11625b3756454 to your computer and use it in GitHub Desktop.
test.js
const data = [
{
roomId: 1,
rateId: 2,
name: 'room 1'
},
{
roomId: 1,
rateId: 2,
name: 'room 2'
},
{
roomId: 1,
rateId: 3,
name: 'room 3'
},
{
roomId: 1,
rateId: 4,
name: 'room 4'
},
]
const grouped = _(data).groupBy((item)=>`${item.roomId}--${item.rateId}`)
const aggregated = grouped.mapValues( v => _.assign(...v))
console.log(JSON.stringify(grouped, null, 2))
console.log(JSON.stringify(aggregated, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment