Skip to main content
pd0001
April 21, 2022
Question

Question related to print the array

  • April 21, 2022
  • 3 replies
  • 0 views

QUESTION 1> Suppose we have 1 array : local!arr : {a,b,b,c,c,c,d,d,d,d}. Then how we will print in the pattern like

a,

  b,b

   c,c,c

   d,d,d,d.

QUESTION 2>Suppose we have 2 - arr1: {"apple","banana","mango"},  arr2:{"a","b","c"}.

How we will print if we choose "a" then it should print "apple" , if we choose "b" then it should print "banana" , if we choose "c" , it should print "mango".

    3 replies

    gopalk2865
    Participating Frequently
    April 21, 2022

    Hi [mention:6653845e210e4be9b48fd3b0ffed120b:e9ed411860ed4f2ba0265705b8793d05], for your first question my solution would be below,

    a!localVariables(
      local!arr : {"a","b","b","c","c","c","d","d","d","d"},
      a!forEach(
        items: union(local!arr,local!arr),
        expression: joinarray(repeat(fv!index,fv!item))
        )
    )

    and for your second question , you can use the latest function  a!match() to achieve what you want.

    pd0001
    pd0001Author
    April 21, 2022

    Hi gopalk, I am still not able to solve 2nd problem when i am choosing input from 2nd array via rule input then it should print from array 1.

    gopalk2865
    Participating Frequently
    April 21, 2022

    Hi, in simple way you can implement like this, there are other methods as well like creating decision table . Check your use case and then decide the approach.