I want to map an array of objects to output an immutable map that is grouped by a specific object.
array looks like
[
{id:1, time:19072016},
{id:2, time:19072016},
{id:3, time:19072015},
]
output im seeking is
[
byId: {
1:{id:1, time:19072016},
2:{id:2, time:19072016},
3:{id:3, time:19072015},
},
byTime: {
19072016:[1,2],
19072015:[3],
}
]
What is the most efficient way to do this using immutablejs or seamlessly immutable?
im currently using abbreviation like:
array.reduce( (final,row) =>final.setIn(['byId',row.id],row) ,
Immutable.Map({byId:{},byTime:{}});
this conclusion on indices as I want, but the problem with byTimeis that I need to combine, not overwrite.
I tried with seamless-immutable I did:
Seamless(arr).toObject(i=>[i.id,i])
Seamless(arr).toObject(i=>[i.time,[i.id]])