返回顶部

收藏

Convert a hash to set and divide

更多
require 'set'
connections = { 1 => 2, 2 => 3, 3 => 1, 4 => 1 }
[1,2,3,4].to_set.divide { |x,y| connections[x] == y }
# => #<Set: {#<Set: {1, 2, 3}>, #<Set: {4}>}>

标签:Ruby,集合

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2016-12-25 16:45:49The intersection is the set of values that appear in both by 好好学习啊
  2. 2015-12-19 11:02:24Custom class based range by JustForFly
  3. 2016-01-16 09:59:29Sort with block by 胡晋
  4. 2016-01-20 16:52:19Each loop by zetaliang
  5. 2016-08-28 10:10:01Create set with Set.new by LeoSun
  6. 2016-08-28 13:57:54inorder / preorder / postorder by 永明
  7. 2016-09-16 19:29:52Classify a set into three by 永明
  8. 2016-01-13 11:51:16Create Your queue by 永明
  9. 2016-01-25 10:05:50The union is the set of values that appear in either by digua
  10. 2016-08-28 10:28:28Is it in a set by 永明
  11. 2016-08-28 14:18:49search a tree by digua

发表评论