提取数字范围“值”来自 Ruby Hashtable 或 Json 对象
我对 Ruby (1.8.7) 很陌生,并且希望能够从哈希表中提取特定数值范围内的值(无需迭代这些值)。
如果我有哈希表:
my_hash = {
55 => {:value=>61, :rating=>147},
89 => {:value=>72, :rating=>200},
78 => {:value=>64, :rating=>300}
}
我将如何解析哈希表以便返回 rating=>300(如果范围为 250..350)?或者,我将根据评级值对哈希表进行排序,并单独迭代检查每个值。
谢谢,
迈尔斯。
I am quite new to Ruby (1.8.7), and would like to be able to extract values from a Hashtable which are within a specific numeric range (without having to iterate through the values).
If I have Hashtable with:
my_hash = {
55 => {:value=>61, :rating=>147},
89 => {:value=>72, :rating=>200},
78 => {:value=>64, :rating=>300}
}
How would I parse the Hashtable so the rating=>300 was returned (if a range of 250..350) was specified? Alternatively I will sort the Hashtable on the rating value and iterate checking each value individually.
Thanks,
Miles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要返回评级范围内的 my_hash 条目:
To return my_hash entries within a range of ratings: