I have two arrays of hashes
rtg
with keysid, position_id, valid_from, valid_to
inv
with keysid, position_id, date
Examples look like this:
rtg=[{:id=>7, :position_id=>3, :valid_from=>Tue, 05 Sep 2017 10:00:00 EEST +03:00, :valid_to=>Tue, 05 Sep 2017 10:59:59 EEST +03:00},
{:id=>6, :position_id=>3, :valid_from=>Mon, 04 Sep 2017 22:00:00 EEST +03:00, :valid_to=>Mon, 04 Sep 2017 23:59:59 EEST +03:00},
{:id=>1, :position_id=>2, :valid_from=>Mon, 04 Sep 2017 07:00:00 EEST +03:00, :valid_to=>Mon, 04 Sep 2017 08:00:00 EEST +03:00}]
inv=[{:id=>23, :position_id=>3, :date=>Tue, 05 Sep 2017 10:10:00 EEST +03:00},
{:id=>17, :position_id=>3, :date=>Mon, 04 Sep 2017 22:45:00 EEST +03:00},
{:id=>11, :position_id=>3, :date=>Mon, 04 Sep 2017 07:20:00 EEST +03:00}]
I need to create array of arrays with id
pairs from rtg
and inv
hashes where
1) position_id
match and
2) date
from inv
is in rage of valid_from
& valid_to
from rtg
How do I do this, please?
In my example above result would be:
result = [[7,23],[6,17]]
You could use nested
each
to compare each item in both arrays, grabbing theid
s for those items that match the conditions; for example: