hi,
I am trying to split a map based on user input
local!data: { a!map(id: 1, name: "Alice", age: 10, city: "New York",school:"NewYork"), a!map(id: 2, name: "Bob", age: 12, city: "Los Angeles",school:"NewYork"), a!map(id: 3, name: "Charlie", age: 13, city: "Chicago",school:"NewYork"), a!map(id: 4, name: "David", age: 14, city: "Houston",school:"NewYork") },
if I give input : age
I should get two
local!data1:{
a!map(id: 1, name: "Alice", age: 10, ),a!map(id: 2, name: "Bob", age: 12, ),a!map(id: 3, name: "Charlie", age: 13, ),a!map(id: 4, name: "David", age: 14, )} and
local!data2:{a!map(city: "New York",school:"NewYork"),
a!map(city: "Los Angeles",school:"NewYork"),a!map(city: "Chicago",school:"NewYork"),a!map(city: "Houston",school:"NewYork")}
is there a way to achieve this , I tried ldrop and rdrop, it doesnt give output as expected
Discussion posts and replies are publicly visible
hi kowsalyavijayan May I know what your use case is and what you are trying to achieve
Your requirement is unclear from here.
kowsalyavijayan said:I should get two local!data1:{
Are you expecting two different dictionaries based on your input? Also what criteria are you looking at for the split.
You can easily iterate on the input maps, and, based on conditions, create two new maps for each.
I am not sure what you are trying to achieve but here is the sample code that matches your requirement
a!localVariables( local!data: { a!map( id: 1, name: "Alice", age: 10, city: "New York", school: "NewYork" ), a!map( id: 2, name: "Bob", age: 12, city: "Los Angeles", school: "NewYork" ), a!map( id: 3, name: "Charlie", age: 13, city: "Chicago", school: "NewYork" ), a!map( id: 4, name: "David", age: 14, city: "Houston", school: "NewYork" ) }, local!keys: a!keys(local!data[1]), local!inputindex: if( a!isNullOrEmpty(ri!input), "", if( contains(local!keys, ri!input), wherecontains(touniformstring(ri!input), local!keys), null ) ), local!keys2: if( a!isNullOrEmpty(local!inputindex), null, rdrop( local!keys, (length(local!keys) - local!inputindex) ) ), local!keys3: if( a!isNullOrEmpty(local!inputindex), null, ldrop(local!keys, local!inputindex) ), local!data1: if( a!isNullOrEmpty(local!inputindex), null, cast( 253, a!forEach( local!data, createdictionary( local!keys2, property(fv!item, local!keys2, null) ) ) ) ), local!data2: if( a!isNullOrEmpty(local!inputindex), null, cast( 253, a!forEach( local!data, createdictionary( local!keys3, property(fv!item, local!keys3, null) ) ) ) ), { if( a!isNullOrEmpty(local!inputindex), "Enter right keyword", { local!data1, local!data2 } ) } )