如何从ruby中哈希数组中的范围中找到最小值?(How to find the minimum value from the ranges in array of hashes in ruby?)

编程入门 行业动态 更新时间:2024-10-18 03:25:12
如何从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 #=> 10

Demo

更多推荐

本文发布于:2023-07-22 09:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219131.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组中   最小值   中找到   中哈希数   ruby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!