Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to combine 2 array

I have 2 arrays of objects, I want to combine both array of objects as one array, by adding 2nd arrays key value pair as 3rd key value pairs for 1st array.

First array

 a = [{:performed_at=>"Aging", :result=>"Not Completed"}, {:performed_at=>"Aging", :result=>"Not Completed"}, {:performed_at=>"Mar 25, 2022", :result=>"Pass"}]

Second Array

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

b = [{:line_item=>"10C-1648150055"}, {:line_item=>"10D-1648150055"}, {:line_item=>"10E-1648150055"}]

I want the result array of objects like this

[{:performed_at=>"Aging", :result=>"Not Completed", :line_item=>"10C-1648150055"}, {:performed_at=>"Aging", :result=>"Not Completed",:line_item=>"10D-1648150055"}, {:performed_at=>"Mar 25, 2022", :result=>"Pass",:line_item=>"10E-1648150055"}]

Kindly help

>Solution :

Something like the this should work:

a.map.with_index do |el, index|
 el.merge(b[index])
end
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading