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