【发布时间】:2020-03-15 14:50:32
【问题描述】:
我的大脑在爆炸。我需要创建一个函数来接受输入并将其转换为另一种格式。
从对象数组中,它应该创建一个信息对象,其中包含一个按标签排序的数组,并且列表中的值也应该有特殊的顺序。我需要找到修复它的方法或算法。
输入是这样的:
[
{
"information": [
{
"label": "Wichtigste Leistungen",
"list": [
{
"list": {
"1953-24uxno": {
"rows": [1]
}
}
},
{
"list": {
"1953-24uxno": {
"rows": [2]
}
}
}
]
},
{
"label": "Allgemein",
"list": [
{
"list": {
"1953-24uxno": {
"rows": [11]
}
}
},
{
"list": {
"1953-24uxno": {
"rows": [12]
}
}
}
]
}
]
},
{
"information": [
{
"label": "Wichtigste Leistungen",
"list": [
{
"list": {
"1953-obbpw8": {
"rows": [3]
}
}
},
{
"list": {
"1953-obbpw8": {
"rows": [4]
}
}
}
]
},
{
"label": "Allgemein",
"list": [
{
"list": {
"1953-obbpw8": {
"rows": [31]
}
}
},
{
"list": {
"1953-obbpw8": {
"rows": [32]
}
}
}
]
}
]
}
]
输出:
{
"information": [
{
"label": "Wichtigste Leistungen",
"list": [
{
"list": {
"1953-24uxno": {
"rows": [1]
},
"1953-obbpw8": {
"rows": [3]
}
}
},
{
"list": {
"1953-24uxno": {
"rows": [2]
},
"1953-obbpw8": {
"rows": [4]
}
}
}
]
},
{
"label": "Allgemein",
"list": [
{
"list": {
"1953-24uxno": {
"rows": [11]
},
"1953-obbpw8": {
"rows": [31]
}
}
},
{
"list": {
"1953-24uxno": {
"rows": [12]
},
"1953-obbpw8": {
"rows": [32]
}
}
}
]
}
]
}
【问题讨论】:
-
到目前为止,您尝试解决什么问题?可以分享一下代码吗?
-
请访问help center查看内容和How to Ask。提示:发布努力和代码。
-
所以...按
.information.label分组并连接所有.list.lists? -
搜索 javascript reduce 组
标签: javascript algorithm ecmascript-6