jeudi 2 juillet 2015

Get key from hash if value in it zero

I have 3 array region ,min,max.If min and corresponding max is both 0 then I want to get the corresponding region into an array.

region=["A","B","C","D","E","F","G"]
min= ["0","0","0","200","400","0","0"]
max= ["0","0","0","1000","1000","0","0"]

Expected output :

output=["A","B","C","F","G"]

In the above..ABCFG has corresponding min and max both 0..so I want those region valuse..i.e regions which has both min and max 0

I tried below but no able to proceed furthur

Hash[region.zip([min.map(&:to_i),max.map(&:to_i)].transpose)]

//output
{"A"=>[0, 0], "B"=>[0, 0], "C"=>[0, 0], "D"=>[200, 1000], "E"=>[400, 1000], "F"=>[0, 0], "H"=>[0, 0]}

Aucun commentaire:

Enregistrer un commentaire