on 2023 Feb 28 7:26 AM
I have below json in memory-
[
{
"2 BHK":[0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0]
},
{
"1 BHK":[0,1,0]
}
]
I want to show above data like below-
[
{
"bhk_type":"2 BHK"
"sold":2, (count of all the 1's)
"unsold":20 (count of all the 0's)
},
{
"bhk_type":"1 BHK"
"sold":1, (count of all the 1's)
"unsold":2 (count of all the 0's)
}
]
I am using pluck and @root but not getting correct result. Please help
Request clarification before answering.
I did it this way, where memory.test holds the original string:
[{{#eachJoin memory.test}} {{#eachJoin @this}} { "bhk_type" : "{{@key}}", "sold": {{sum @this}} , "unsold": {{subtract (length @this) (sum @this) }} }{{/eachJoin}} {{/eachJoin}} ]
And here is the result
I assumed the string would always be in the exact format you provided, though varying BHK strings and length of number strings.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
57 | |
10 | |
8 | |
8 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.