Is there a way to get a map with merged keys from a map of map, or from a map of map of map.
I’ve been playing with d3.group(iterable, d=> d.key1, d=>key2)
, (merci @Fil for this d3-group notebook )
my above d3.group(...
produce a map like
{
"foo" => {"Mon" => [obj1, obj2],
"Wed" => [obj3]},
"baz" => {"Tue" => [obj4, obj5, obj6],
"Wed" => [obj7, obj8]},
...
}
Nice!
But then how do I flatten it so I get this
{
"foo-Mon" => [obj1, obj2],
"foo-Wed" => [obj3],
"baz-Tue" => [obj4, obj5, obj6],
"baz-Wed" => [obj7, obj8]
...
}
I made this function to do the job
function upliftkey(res, [k, arr]) {
return arr.reduce((acc, [nk, nv]) => Object.assign(res, ({[`${k}-${nk}`]: nv})), {})
}
That I use in a reduce
like so d3-array.groups(data, d=>d.key1, d=>d.key2).reduce(upliftkey, {})
. It’s ok, but my recursive attempt to flatten an aribtray number of nested group has fail.
So my question. Is it already in d3 ? and if not do you think it could be included ?