input : {{1,3},{2,3},{4,5},{5,6}}
output : {3,6,20,30}
We have to get product of each item(i.e list) in the array.
Please help me out with this issue
Discussion posts and replies are publicly visible
a!localVariables( local!a: { a!map(input: { 1, 3 }), a!map(input: { 2, 3 }), a!map(input: { 4, 5 }), a!map(input: { 5, 6 }) }, local!output: a!forEach( local!a.input, reduce(fn!product, 1, fv!item, 1) ), local!output )
your input will convert into one single array instead of being separated into 4 different array if you declare using curly brackets. You have to declare using map to maintain the structure
Is there any way to convert the list of list(i.e {{1,3},{2,3},{4,5},{5,6}}) to a
list of map (i.e
{
a!map(input: { 1, 3 }), a!map(input: { 2, 3 }), a!map(input: { 4, 5 }), a!map(input: { 5, 6 }) },)
Appian does not handle list-of-lists well at all (and never has). You can attempt to call a!forEach() over your list-of-lists, but there's no guarantee it won't just iterate over each item individaully. It also largely depends on where you're getting your input data, which you haven't specified.
It's just an expression problem for practice
the problem is, in almost all contexts, a plain list-of-lists is handled by the Appian parsers as a flattened array (and it's hard or impossible to predict when it will or won't be, other than trial-and-error). It's always safer to assume it will be.