Hello all, I have a question that I think it should be easy but I cannot figure it out, and also I cannot see any response in this forum. If I have a a!forEach within another a!forEach, is there a way of refering to the items of the outer loop, within the first loop? Example to understand with non real data:
I have two lists:
local!text: {"1111 - GREAT", "1000 - BAD", "5600 - MEDIUM"}
local!words: {"GREAT", "MEDIUM"}
as you can see, "text" is a list of text, and each string contains a code a "-" and a word. I want to create a nested loop that returns a list with the codes only when the words contained in the list "words" are in the list a.In this particular example: {"GREAT", "MEDIUM"} because "GREAT" is included in "1000 - GREAT" and "MEDIUM" is included in "5600 - MEDIUM".
I woud like to iterate though every item of list "words", check if it is in any item of list "text", and then, moved to the next item of list "words". something like.
a!forEach( items: local!words, expression: a!forEach( items: local!text, expression: if(contains( fv!itemintext,fv!iteminwords), fv!itemintext[fv!index], null ) ) )
in other languajes it will be really easy because for every loop you could assign an identifier, as for example in python you would be able to do something like:
for w in words:
for t in text:
I hope you can help me with this one
Discussion posts and replies are publicly visible
using a nested loop, the below code should resolve your question
a!localVariables( local!text: { "1111 - GREAT", "1000 - BAD", "5600 - MEDIUM" }, local!words: { "GREAT", "MEDIUM" }, local!output: a!forEach( items: local!words, expression: if( contains( a!forEach( items: local!text, expression: split(fv!item, " - ")[2] ), fv!item ), fv!item, null ) ), remove(local!output, wherecontains(null, local!output)) )
Hello Zukiswa,
Thank you very much for your answer! It looks direct and simple! Great. Do you think I could also use this approach if I later want to create another list of strings with the codes, e.g. {"1111","5600"}?
Thanks in advance!