Good day! There is an array of such hashes:

[{:album_id => 1, :stream => 15}, {:album_id => 2, :stream => 10}] 

and so on. How can we convert this array in order to end up with an array of this type:

 [{1 => 15}, {2 => 10}] 

I am very grateful for the help. Thank you in advance.

    1 answer 1

    There is such a map iterator:

     array = [{:album_id => 1, :stream => 15}, {:album_id => 2, :stream => 10}] result = array.map { |hash| { hash[:album_id] => hash[:stream] } } result #=> [{1=>15}, {2=>10}]