返回顶部

收藏

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-02-17 14:43:31Classify set elements as even or odd by Jamin
  2. 2016-08-28 12:09:13Inspect a set by 好好学习啊
  3. 2016-08-27 21:28:07include Comparable by 好好学习啊
  4. 2016-08-28 12:16:49Compare two sets by LeoSun
  5. 2015-12-06 09:47:36to string by 好好学习啊
  6. 2015-12-30 10:38:27Set subtraction by 杨洋
  7. 2016-01-29 09:46:42Easing the Delegation Blues by 胡晋
  8. 2016-02-22 20:29:27Create set with constant values by Loli控
  9. 2016-03-09 13:03:04Create Your tree by JustForFly
  10. 2016-08-27 21:39:08get Enumerable involved by LeoSun
  11. 2016-08-28 12:27:21Divide with block by jeffsui

发表评论