Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this structure:

$ArrayX = [8349310431,8349314513,......]
$ArrayY = [667984788,667987788,......]
$ArrayZ = [148507632380,153294624079,.....]

$range_map = $ArrayX.zip([$ArrayY.map(&:to_i), 
             $ArrayZ.map(&:to_i)].transpose).sort

puts $range_map ={[8349310431=>[667984788, 148507632380],  
                 8349314513=>[667987788, 153294624079]}

I need the key to be compared with the rest of the keys and if the subtraction between keys is lower than 100, that key to print

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

I corrected your code also as per your need, and solved further,

$ArrayX = [8349310431,8349314513]
$ArrayY = [667984788,667987788]
$ArrayZ = [148507632380,153294624079]

$range_map = $ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort

$ArrayX = [8349310431,8349314513]
 => [8349310431, 8349314513]
$ArrayY = [667984788,667987788]
 => [667984788, 667987788]
$ArrayZ = [148507632380,153294624079]
 => [148507632380, 153294624079] 

$range_map = Hash[$ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort]
 => {8349310431=>[667984788, 148507632380], 8349314513=>[667987788, 153294624079]}

keys = $range_map.keys
valid_keys = keys.select { |k| keys.detect { |x| (x-k).abs > 100 } }
$range_map.slice(*valid_keys)

If particular key is having difference more than 100 with one of rest of keys then it will be valid for filtering.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...