cancel
Showing results for 
Search instead for 
Did you mean: 

Replace value according to its poition

KTsnap
New Contributor III

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 "$"
14 REPLIES 14

rashmi
New Contributor III

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?
communityhelp2

communityhelp1

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))

image

rashmi
New Contributor III

Hi @alchemiz its not my requirement actually i had listed my requirement above i am updating value obtained from row array to group array

$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 )

image

rashmi
New Contributor III

hi @alchemiz thanks for helping but thats not exact requirement actually there are two arrays in input called row and group
inputcommunity
and each looks like this as shown below
secondarray
firstarray
so according to position values (rowid & colid) need to update values of second array (group array)only
expected output:
outputcommunity