Question: How can I transform `array1` into `hash1` in Ruby?

`array1` looks like this: 

```
    [[80, "X", 12],
     [80, "X", 13],
     [80, "X", 14],
     [80, "X", 15],
     [80, "X", 16],
     [81, "Y", 20],
     [81, "Y", 21],
     [81, "Y", 22],
     [81, "Y", 23],
     [81, "Y", 24]]

```

`hash1` looks like this:

```
[['id' => 80, 'type' = >'X', numbers => {12,13,14,15,16}],
       ['id' => 81, 'type' = >'Y',numbers => {20,21,22,23,24}]]

```

Answer: 
```
array1
.group_by{|id, type, _| [id, type]}
.map{|(id, type), a| {"id" => id, "type" => type, "numbers" => a.map(&:last)}}
# => [
#      {"id"=>80, "type"=>"X", "numbers"=>[12, 13, 14, 15, 16]},
#      {"id"=>81, "type"=>"Y", "numbers"=>[20, 21, 22, 23, 24]}
#    ]

```
You would have to iterate through your array1 and start assigning values into the hash that you want using basic comparisons (if - else, group\_by and mapping) and keeping history of the previous ids.

There's no such a ruby method that does this "magically".