Похожие чаты

Hey javascript.. I am trying to write a recursive groupBy

function, that allows for not-existing keys. This is what I have so far using ramda:
nest = R.curry((props, items) =>
R.isEmpty(props) ? items
: R.map(nest(R.tail(props)),
R.groupBy(R.prop(R.head(props)), items)))
However, it also nests under undefined or null if the property does not exist.. Which is not what I want.
Here is an example input:
nest(['a', 'b'], [{a:2}, {a:1, b: 4}, {a:2, b:2}])
I get this output
{
"1": {
"4": [
{
"a": 1,
"b": 4
}
]
},
"2": {
"2": [
{
"a": 2,
"b": 2
}
],
"undefined": [
{
"a": 2
}
]
}
}
but instead I would like to get this:
{
"1": {
"4": [
{
"a": 1,
"b": 4
}
]
},
"2": {
"2": [
{
"a": 2,
"b": 2
}
],
{
"a": 2
}
}
}

1 ответов

6 просмотров
Misan- Автор вопроса

oh wait. this cannot work.. I cannot have a value without a label.. 🤔

Похожие вопросы

Обсуждают сегодня

Карта сайта