我正在处理一个相当复杂的情况:我有3个数组,如下所示。Values
数组中的值每隔5秒就会更改为true
或false
。
var Config = [{
"rdd": "Transducer Failure",
"performance": true,
"agc": false,
"snr": true,
"sos": false,
"flowvel": true
},
{
"rdd": "Detection Problem",
"performance": false,
"agc": true,
"snr": false,
"sos": true,
"flowvel": false
}
]
配置数组将包含所有示例的配置,所有示例均适用于相应的rdd
。例如,"传感器故障"将包含performance
、snr
和flowvel
,而不是所有其他字段;ds将适用于agc
和sos
。
var Instance = [{
"U": [{
"performance": "abc",
"agc": "xyz",
"snr": "pqr",
"sos": "vns",
"flowvel": "mns"
}],
"Y": [{
"performance": "a",
"agc": "b",
"snr": "c",
"sos": "d",
"flowvel": "e"
}]
}]
示例将具有配置数组为的示例:
var Values = [{
"abc": true,
"xyz": false,
"pqr": true,
"vns": false,
"mns": true,
"a": true,
"b": false,
"c": false,
"d": true,
"e": true
}]
值将具有相对于示例值的值。
我想要新的对象数组匹配以下条件..
1.如果Config
中的值是true
,例如,如果配置数组中的performance
、snr
为真,则它Map到Instance
数组中的相应值,例如,如果performance
是true
,则它将Map到Instance
数组中的"abc",并且如果performance
为假,则它将返回NA
Config
数组中键的值将是Values
数组中键的值。例如,如果performance
是true
,则将其Map到示例"abc",如果"abc"的值是true
,则performance
的值将是true
或false
。其次,如果Config
本身中performance
值为false
,则返回"NA"
期望产量
result = [{
"U": [{
"rdd": "Transducer Failure",
"performance": true,
"agc": "NA",
"snr": true,
"sos": "NA",
"flowvel": true
},
{
"rdd": "Detection Problem",
"performance": "NA",
"agc": false,
"snr": "NA",
"sos": false,
"flowvel": "NA"
}
],
"Y": [{
"rdd": "Transducer Failure",
"performance": true,
"agc": "NA",
"snr": false,
"sos": "NA",
"flowvel": true
},
{
"rdd": "Detection Problem",
"performance": "NA",
"agc": false,
"snr": "NA",
"sos": true,
"flowvel": "NA"
}
]
}]
1条答案
按热度按时间k10s72fa1#
下面是我的解决方案。我使用
Object.keys
来获取键名称,并使用数组表示法在结果对象键中分配动态名称。Object.assign
用于在最终结果中仅获取一个对象,即resultArray