Array element assignment from one segment to other when length of array is dynamic
Here is the sample challenge,
below is input and expected output.
items can increase dynamically, but the “WORK” field of REFILL should get assigned under NAME field of TOTLITEM.
input payload :
[
{
“REFILL”:{
“item”:[
{
“ITEM”:“1”,
“TEXT”:“first”,
“NAME”:“laptop”,
“WORK”:“office”
},
{
“ITEM”:“2”,
“TEXT”:“second”,
“NAME”:“mobile”,
“WORK”:“marketing”
}
]
}
},
{
“TOTLITEM”:{
“item”:[
{
“ITEM”:“1”,
“TEXT”:“first”,
“NAME”:“none”
},
{
“ITEM”:“2”,
“TEXT”:“second”,
“NAME”:“none”
}
]
}
}
]
expected output :
[
{
“REFILL”:{
“item”:[
{
“ITEM”:“1”,
“TEXT”:“first”,
“NAME”:“laptop”,
“WORK”:“office”
},
{
“ITEM”:“2”,
“TEXT”:“second”,
“NAME”:“mobile”,
“WORK”:“marketing”
}
]
}
},
{
“TOTLITEM”:{
“item”:[
{
“ITEM”:“1”,
“TEXT”:“first”,
“NAME”:“none”
“WORK”:“office”
},
{
“ITEM”:“2”,
“TEXT”:“second”,
“NAME”:“none”
“WORK”:“marketing”
}
]
}
}
]
Thanks