Created
June 25, 2019 11:01
-
-
Save tuananh/8f9bfd3719d8e6b45fd11625b3756454 to your computer and use it in GitHub Desktop.
test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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