Forum Discussion
$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 )
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:
- alchemiz3 years agoContributor III
Glad to be of help 🤘
- alchemiz3 years agoContributor III
My bad, I got the charCode wrong it should be 64 😀
$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 )
- rashmi3 years agoNew Contributor III
hi @alchemiz the column keys in group array maynot be characters like A,B,C… its suppose to map based on the position like col1,col2 etc the expression suggested by @bojanvelevski
$group.map((x,index)=>$[‘@id’] == index + 1 ? (x.mapValues((v,k)=> $col.find(e => e[‘@id’]-1 == x.keys().indexOf(k)) != null ? $col.find(e => e[‘@id’]-1 == x.keys().indexOf(k) ).get(‘$’) : v)) : x)
works irrespective of column name in group array but its should be tweaked to satisfy my input becoz in which he had metioned $[‘@id’] comes in as filed but in my case it comes in as an array element like this jsonPath($, “row[][‘@id’]") and also $col comes in as an array but in my case it comes in under row array like this jsonPath($, "row[].col”), so i need help in adjusting the above expression to satisfy my input.Please could u help 😔 - alchemiz3 years agoContributor III
Just replace the criteria when checking for the col object…
$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’] == (g.keys().indexOf(key) + 1)) instanceof Object ? $row.find((a,b,c)=> a[‘@id’] == i + 1)[‘col’].find((x,y,z)=> x[‘@id’] == (g.keys().indexOf(key) + 1)).get(‘$’,val) : val ) : g )