如何从ruby中哈希数组中的范围中找到最小值?(How to find the minimum value from the ranges in array of hashes in ruby?)
我有下面的哈希数组
z = {"RANGE"=>[{"10-50"=>"5"}, {"50-100"=>"15"}, {"100-150"=>"25"}]}如何将输出设为10
I have the below array of hashes
z = {"RANGE"=>[{"10-50"=>"5"}, {"50-100"=>"15"}, {"100-150"=>"25"}]}How can I get output as 10
最满意答案
您可以尝试以下方法:
z["RANGE"].map(&:keys).flatten.map(&:to_i).min #=> 10演示
You can try the following:
z["RANGE"].map(&:keys).flatten.map(&:to_i).min #=> 10Demo
更多推荐
发布评论