Hi Sven, Sam,
I wrote the following piece of code to detect the ID’s in an array that are present in another array. My question: is there a way to improve on this? Thanks!
{% comment %}Test array (eg id's of all agenda points){% endcomment %}
{% assign str_Test = '0|1|2|3|4|5|7' %}
{% assign arr_Test = str_Test | split:'|' %}
{% assign int_arr_Test_size = arr_Test.size | minus:1 %}
{% comment %}Test array (eg id's of agenda points that have been selected){% endcomment %}
{% assign str_Totaal = '0|1|2|5|6' %}
{% assign arr_Totaal = str_Totaal | split:'|' %}
{% assign int_arr_Totaal_size = arr_Totaal.size | minus:1 %}
{% comment %}Initialize result{% endcomment %}
{% assign str_result = '' %}
{% comment %}Question: which agenda points of arr_Test are present in arr_Totaal (1) or not present (0){% endcomment %}
{% for Test_Element in arr_Test %}
{% assign int_Test_Element_Counter_Base1 = int_Test_Element_Counter_Base1 | plus:1 %}
{% assign int_Test_Element_Counter_Base0 = int_Test_Element_Counter_Base1 | minus:1 %}
{% assign int_Totaal_Element_Counter_Base1 = 0 %}
{% for Totaal_Element in arr_Totaal %}
{% assign int_Totaal_Element_Counter_Base1 = int_Totaal_Element_Counter_Base1 | plus:1 %}
{% assign int_Totaal_Element_Counter_Base0 = int_Totaal_Element_Counter_Base1 | minus:1 %}
{% if Test_Element == arr_Totaal[int_Totaal_Element_Counter_Base0] %}
{% break %}
{% endif %}
{% endfor %}
{% if int_Totaal_Element_Counter_Base0 == {{int_arr_Totaal_size}} %}
{% comment %}For every element except last one{% endcomment %}
{% if int_Test_Element_Counter_Base0 < {{int_arr_Test_size}} %}
{% assign str_result = str_result | append:0 | append:'|' %}
{% comment %}For last element{% endcomment %}
{% else %}
{% if arr_Test[int_Test_Element_Counter_Base0] == arr_Totaal[int_Totaal_Element_Counter_Base0] %}
{% assign str_result = str_result | append:'1' | append:'|' %}
{% else %}
{% assign str_result = str_result | append:'0' | append:'|' %}
{% endif %}
{% endif %}
{% else %}
{% assign str_result = str_result | append:1 | append:'|' %}
{% endif %}
{% endfor %}
str_result {{ str_result }}