Conditional summing

Hi,

In case one of my colleagues might need to make a conditional sum:

    Doel: de voorwaardelijke som maken van een array gebaseerd op een andere array

{% comment %}A = 25, B = 7, C = 8, D = 3{% endcomment %}

{% assign str_persons = 'A|B|A|C|B|D' %}
{% assign str_amounts = '10|5|15|8|2|3' %}

{% assign arr_persons = str_persons | split:'|' %}
{% assign arr_amounts = str_amounts | split:'|' %}

{% assign arr_persons_unique = arr_persons | uniq %}
{% assign int_persons_unique_counter = 0 %}

{% for person_unique in arr_persons_unique %}

  {% assign int_ConditionalSum_person_unique = 0 %}
  {% assign int_persons_counter = 0 %}

  {% for person in arr_persons %}

    {% if person == arr_persons_unique[int_persons_unique_counter] %}
      {% assign int_ConditionalSum_person_unique = int_ConditionalSum_person_unique | plus:arr_amounts[int_persons_counter] %}
    {% endif %}
    {% assign int_persons_counter = int_persons_counter | plus:1 %}
  
  {% endfor %}
    
    {% assign str_ConditionalSum_person_unique = str_ConditionalSum_person_unique | append:int_ConditionalSum_person_unique | append:'|' %}
    
    {% assign int_persons_unique_counter = int_persons_unique_counter | plus:1 %}

{% endfor %}

{% assign str_ConditionalSum_person_unique = str_ConditionalSum_person_unique | slice:0,str_ConditionalSum_person_unique.size-1 %}

{% assign arr_ConditionalSum_person_unique = str_ConditionalSum_person_unique | split:'|' %}


unique persons:           {{arr_persons_unique | join:'|'}}

total amounts per person: {{arr_ConditionalSum_person_unique | join:'|'}}