Ruby:Hash 排序
people = {:fred => 23,:joan => 18,:pete => 54
}
年龄排序:
people.values.sort # => [18, 23, 54]
姓名排序:
people.sort_by { |name, age| age }# => [[:joan, 18], [:fred, 23], [:pete, 54]]
或者
people.sort
一个复杂点的hash
people = {:fred => { :name => "Fred", :age => 23 },:joan => { :name => "Joan", :age => 18 },:pete => { :name => "Pete", :age => 54 }
}
people.sort_by { |k, v| v[:age] }# => [[:joan, {:name=>"Joan", :age=>18}], [:fred, {:name=>"Fred", :age=>23}],[:pete, {:name=>"Pete", :age=>54}]]
Ruby:Hash 排序相关推荐
- ruby hash方法_Ruby中带有示例的Hash.invert方法
ruby hash方法 Hash.invert方法 (Hash.invert Method) In this article, we will study about Hash.invert Meth ...
- ruby hash方法_Ruby中带有示例的Hash.select方法
ruby hash方法 哈希选择方法 (Hash.select Method) In this article, we will study about Hash.select Method. The ...
- ruby hash方法_Ruby中带有示例的Hash.default(key = nil)方法
ruby hash方法 Hash.default(key = nil)方法 (Hash.default(key=nil) Method) In this article, we will study ...
- ruby hash方法_Ruby中带有示例的Hash.length方法
ruby hash方法 哈希长度方法 (Hash.length Method) In this article, we will study about Hash.length Method. The ...
- ruby hash方法_Ruby中带有示例的Hash.flatten方法
ruby hash方法 哈希平化方法 (Hash.flatten Method) In this article, we will study about Hash.flatten Method. T ...
- ruby hash方法_Ruby中带有示例的Hash.key?(obj)方法
ruby hash方法 Hash.key?(obj)方法 (Hash.key?(obj) Method) In this article, we will study about Hash.key?( ...
- ruby hash方法_Ruby中带有示例的Hash.rassoc(obj)方法
ruby hash方法 Hash.rassoc(obj)方法 (Hash.rassoc(obj) Method) In this article, we will study about Hash.r ...
- ruby hash方法_Ruby中带有示例的Hash.keys方法
ruby hash方法 哈希键方法 (Hash.keys Method) In this article, we will study about Hash.keys Method. The work ...
- ruby hash方法_Hash.fetch()方法以及Ruby中的示例
ruby hash方法 Hash.fetch()方法 (Hash.fetch() Method) In this article, we will study about Hash.fetch() M ...
- ruby hash方法_Ruby中带有示例的Hash.rehash方法
ruby hash方法 Hash.rehash方法 (Hash.rehash Method) In this article, we will study about Hash.rehash Meth ...
最新文章
- 方舟服务器显示队友位置,方舟如何看队友在哪 | 手游网游页游攻略大全
- Redis数据库的初步认识(二)-C/C++连接redis数据库
- 【短文本聚类】TextCluster:短文本聚类预处理模块 Short text cluster
- 什么是SMART原则?
- postgresql 客户端登录配置
- 谎言,统计数据和供应商
- js实现数组翻转(倒序输出)
- 城市地铁类毕业论文文献包含哪些?
- 不记得是哪部电影里的段子了
- 3 天天向上的力量 c语言
- VR游戏开发干货教程:如何创建一个VR项目
- 如何写出令人惊叹的设计文档?
- 最好的跑步耳机推荐、盘点五款公认最好的跑步耳机
- supervisor reload报错及恢复方法
- projectManager
- cesium 街景 vs 三维视图 显卡 知识点.txt
- mac的照片应用照片原图存储位置
- 容器云平台使用体验:DaoCloud
- redis命令配置别名步骤
- 新任技术管理者应该怎样去开始帮助他人?
热门文章
- 全球及中国碳纤维风电叶片市场投资分析与运营潜力预测报告2021-2027年
- 中国环境监测行业现状研究与投资规划分析报告2022-2028年
- 全球及中国铝行业产销需求与未来前景预测分析报告2022-2028年版
- Application Desktop Toolbars 桌面工具栏
- tensorflow基础
- xtraback工具的使用和备份
- erlang mnesia数据库简单应用
- Android 之窗口小部件高级篇--App Widget 之 RemoteViews - 跨到对岸去
- [转] iOS中@class #import #include 简介
- 我们为什么要把方法区分为:静态方法和实例化方法 ?(摘)