Hi, everyone.
I'm learning from "Online Course - Advanced Expressions: Part 2".I have a question about "Exercise: Looping Functions (Online Course | Learning at Appian)".
Exercise: Looping Functions(Online Course | Learning at Appian)
The answer of "Scenario 4" is 1333 (1332 + initial value 1), but adding all the values of "local!sensor" gives 1361.The last value of 29 in the third map seems to be ignored.
a!localVariables( local!sensor: { a!map(data: {125,92,22,63,73,28,19}), a!map(data: {35,65,92,22,63,73,28}), a!map(data: {2,35,65,22,63,73,18,29}), a!map(data: {9,35,65,63,35,28,19}) }, .... .... reduce(fn!sum, 1, local!sensor.data) )
Is the answer 1333 correct?Is this behavior by design?
Regards!
Discussion posts and replies are publicly visible
I see the same behaviour on my Appian 23.1. I changed the code a bit to highlight the problem.
a!localVariables( local!sensor: { a!map(data: {125,92,22,63,73,28,19}), a!map(data: {35, 65,92,22,63,73,28}), a!map(data: {2, 35,65,22,63,73,18,29}), a!map(data: {9, 35,65,63,35,28,19}) }, local!sum1: sum(1, local!sensor[1].data), local!sum2: sum(local!sum1, local!sensor[2].data), local!sum3: sum(local!sum2, local!sensor[3].data), local!sum4: sum(local!sum3, local!sensor[4].data), a!map( reduceResult: reduce(fn!sum, 1, local!sensor.data), manualResult: local!sum4, sumOnly: sum(1, local!sensor.data) ) )
Peter Lewis, do you have any ideas?
Hmm, I'm not sure what's going on, it's possible something isn't getting handled correctly with nested lists - you might want to open a support case. In the meantime, I think you can get the correct results if you flatten the list before passing it to reduce(). I also follow up internally on the course exercise!
thanks, all。
I will open a support case as per your recommendation.
And when I use reduce() I use it differently.