I have found solution for my problem done in JS but i need it done in Ruby (RoR). Here is link to problem and solution: [Find average value for array of hashes using multiple group by](https://stackoverflow.com/questions/34967609/find-average-value-for-array-of-hashes-using-multiple-group-by)

So i have array of hashes that needs to be grouped by keys (first `subject_id` then `element_id`) and then find average values for them. Number of hashes in array is not fixed.

Below is input array:

```
a=[
{:subject_id=>1, :element_id=>2, :value=>55},
{:subject_id=>1, :element_id=>4, :value=>33},
{:subject_id=>1, :element_id=>2, :value=>33},
{:subject_id=>1, :element_id=>4, :value=>1},
{:subject_id=>1, :element_id=>2, :value=>7},
{:subject_id=>1, :element_id=>4, :value=>4},
{:subject_id=>2, :element_id=>2, :value=>3},
{:subject_id=>2, :element_id=>2, :value=>5},
{:subject_id=>2, :element_id=>4, :value=>9}
]

```

Result:

```
b=[
{:subject_id=>1, :element_id=>2, :value=>95},
{:subject_id=>1, :element_id=>4, :value=>38},
{:subject_id=>2, :element_id=>2, :value=>8},
{:subject_id=>2, :element_id=>4, :value=>9}
]

```