How can we show output as given below in appian using expression rule?
output:
1
22
333
4444
55555
Discussion posts and replies are publicly visible
fn!joinarray(fn!repeat(ri!myNumber, ri!myNumber))
Brief explanation:
ri!myNumber is the rule input to the expression, of type Integer.
fn!repeat() generates a list. It takes two parameters:
so here we are generating a list, the length of which is defined by the value of ri!myNumber, and the value of each item is also ri!myNumber
Since your output appears to be a a single string, the fn!joinarray is taking the list and collapsing it into a single value.
If you're actually wanting ALL of the outputs you've defined then you'll need to take the ri!myNumber, generate a list of the numbers from 1 to that number, and then use that list to iterate over the same pattern as expressed in the first code sample, like this:
a!localVariables( local!list: fn!enumerate(ri!myNumber) + 1, a!forEach( items: local!list, expression: fn!joinarray(fn!repeat(fv!item, fv!item)) ) )
Now you have a general purpose Expression which you can pass any number and get the output to conform to the pattern of the example you provided. If you pass the value 5 to the new code you get this output:
Note: if you need the output to be a list of integer you'll have to use the fn!tointeger() to cast from text to integer.
Hi stewart,
Your solution helps.But what if we have String in that place.
like
A
BB
CCC
DDDD
Here you would need to effectively perform a substitution of the number that the previous example has been using with the relevant character:
a!localVariables( local!alphabet: {"A","B","C","D","E"}, local!list: fn!enumerate(ri!myNumber) + 1, a!forEach( items: local!list, expression: fn!joinarray(fn!repeat(fv!item, fn!index(local!alphabet,fv!item,"?"))) ) )
a!flatten( a!forEach( items: enumerate(5) + 1, expression: { joinarray(repeat(fv!index, fv!item), "") } ))
Hi please refer to the below code, just replace the list with the desired input
a!localVariables( local!alphabet: { "A", "B", "C", "D", "E" }, a!forEach( items: local!alphabet, expression: fn!joinarray( fn!repeat( fv!index, fv!item ) ) ) )
a!forEach( items: enumerate(5), expression:joinarray(repeat(fv!index,fv!index)," ") )
a!localVariables( local!stringList: {"A","B","C","D","E"}, a!forEach( items: enumerate(length(local!stringList)), expression:joinarray(repeat(fv!index,local!stringList[fv!index])," ") ) )
How to do for Star/Hill program
*
* * *
* * * * *
logic input will be (Rows * 2 -1)
for eg 1st Row... 1*2-1=1 star
2nd Row 2*2-1=3 stars
3rd Row 3*2-1=5 stars
please suggest the logic
Why would you want to do that in Appian?
Hi Harshit,
Thanks for your response, just to know to get better clarity in functions, if you know logic please let me know
Thanks & Regards
Dinesh