I'm currently facing a rather intricate scenario: I have 3 arrays in JavaScript as depicted below. The values in the Values
array keep changing every 5 seconds to either true
or 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
}
]
The Config array contains configurations for all instances that are applicable for their respective rdd
. For instance, "Transducer Failure" will have performance
, snr
, and flowvel
but not all other fields will be applicable such as agc
and 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"
}]
}]
The Instances array consists of instances with configuration from the Config array:
var Values = [{
"abc": true,
"xyz": false,
"pqr": true,
"vns": false,
"mns": true,
"a": true,
"b": false,
"c": false,
"d": true,
"e": true
}]
Values hold the corresponding values for each instance.
I am aiming to create a new object array that satisfies the following conditions:
If the value in
Config
istrue
; for example, ifperformance
orsnr
in the config array is true, then it corresponds to the respective value in theInstance
array (e.g., ifperformance
istrue
, it maps to "abc" in theInstance
array and ifperformance
is false, it returns NA).The key's value in the
Config
array will match the value of the corresponding key in theValues
array. For example, ifperformance
istrue
, it corresponds to the instance 'abc' and if the value of "abc" istrue
, the value ofperformance
will be eithertrue
orfalse
. Additionally, if the value ofperformance
in theConfig
itself isfalse
, it will return "NA".
Expected output:
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"
}
]
}]