12-09-2022 04:22 AM
Below is the Input
[
{
“@id”: “2”,
“col”: [
{
“@id”: “2”,
“@transable”: “yes”,
“$”: “Replace1”
},
{
“@id”: “3”,
“@transable”: “no”,
“$”: “Replace2”
}
],
“group”: [
{
“A”: “A1”,
“B”: “B1”,
“C”: “C1”,
“D”: “D1”,
“E”: "E1 ",
“F”: “F1”,
“G”: “G1”,
“H”: “”,
“I”: “”
},
{
“A”: “A2”,
“B”: “B2”,
“C”: “C2”,
“D”: “D2”,
“E”: “”,
“F”: “F2”,
“G”: “G2”,
“H”: “”,
“I”: “”
}
]
}
]
expected Output :
[
{
"group": [
{
"A": "A1",
"B": "B1",
"C": "C1",
"D": "D1",
"E": "E1 ",
"F": "F1",
"G": "G1",
"H": "",
"I": ""
},
{
"A": "A2",
"B": "Replace1",
"C": "Replace2",
"D": "D2",
"E": "",
"F": "F2",
"G": "G2",
"H": "",
"I": ""
}
]
}
]
explanantion : @id refers to row number of the group and @id under col refers to the column number of the group where replacement needs to be done with the value of "$"
12-12-2022 05:26 PM
Hi @bojanvelevski , @alchemiz if i try hardcoding the record 1 , record2 in the expression i am getting as expected but how can we dynamically loop across all record?
12-12-2022 05:29 PM
You’re trying to update the value from $row right?
$row.map(r=> r.mapValues((val,key)=> key == ‘col’ ? val.map(c=> c.mapValues((v,k)=> k == ‘$’ ? $group[r[‘@id’] - 1].values()[c[‘@id’] - 1] : v)) : val))
12-12-2022 05:37 PM
Hi @alchemiz its not my requirement actually i had listed my requirement above i am updating value obtained from row array to group array
12-12-2022 05:54 PM
$group.map((g,i)=> $row.find((a,b,c)=> a[‘@id’] == i + 1) instanceof Object ? g.mapValues((val,key)=> $row.find((a,b,c)=> a[‘@id’] == i + 1)[‘col’].find((x,y,z)=> x[‘@id’] == (key.charCodeAt(0) - 64)) instanceof Object ? $row.find((a,b,c)=> a[‘@id’] == i + 1)[‘col’].find((x,y,z)=> x[‘@id’] == (key.charCodeAt(0) - 64))[‘$’] : val ) : g )
12-12-2022 06:06 PM
hi @alchemiz thanks for helping but thats not exact requirement actually there are two arrays in input called row and group
and each looks like this as shown below
so according to position values (rowid & colid) need to update values of second array (group array)only
expected output: