ruby - How to combine two arrays of hashes? -


i querying api information on users given email address. example:

emails = [{'email' => 'example1@test.com'}, {'email' => 'example2@test.com'}, ... ] 

the query hash pass api has in format. api returns array of hashes on information found each user. if there no information returns empty hash in index. results returned in same order queried, i.e. first index of response array info example1@test.com. sample response might this:

response = [{'gender' => 'male', 'age' => '24 - 35'}, {'gender' => 'male'}, ... ] 

how can combine array of email hashes response array such following?

combined = [     {'email' => 'example1@test.com', 'gender' => 'male', 'age' => '24 - 35'},      {'email' => 'example2@test.com', 'gender' => 'male'}, ... ] 

the other way achieve this, basing on @arup rakshit's answer:

emails = [{'email' => 'example1@test.com'}, {'email' => 'example2@test.com'} ] response = [{'gender' => 'male', 'age' => '24 - 35'}, {'gender' => 'male'}] emails.map.with_index { |hash, i| hash.merge(response[i]) } 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -