[Solved] Compare keys of array in RUBY


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.

solved Compare keys of array in RUBY