Given the following collection, what would be the best way to consolidate this data to group by room and make the "names" an array; excluding duplicates, and do not want to use the call the key "name" to make it more dynamic if there are more fields:
var roomAssignments = [{
room: 'Foo',
name: 'Fooname',
other: 'Other'
},{
room: 'Bar',
name: 'Barname',,
other: 'OtherBar'
},{
room: 'Foo',
name: 'Baz',,
other: 'Other'
},{
room: 'Foo',
name: 'Baz',,
other: 'Other'
},{
room: 'Foo',
name: 'Bat',,
other: 'Other'
}];
Desired output:
[{
room: 'Foo',
name: [ 'Fooname', 'Baz', 'Bat' ],
other: ['Other']
}, {
room: 'Bar',
name: [ 'Barname' ],
other: ['OtherBar']
}]
I'm using lodash currently and would prefer that or plain javascript. I think I've been looking at this too long and what I have has about 30 keys that need to be combined into arrays, and I'm looking for the most efficient way to combine all keys into arrays dynamically.