返回顶部

收藏

Divide a set by absolute value

更多
require 'set'

s = [1, 2, 3, -1, -2, -4].to_set

# Divide the set into sets of numbers with the same absolute value.
p s.divide { |x,y| x.abs == y.abs }
# => #<Set: {#<Set: {-1, 1}>,
# =>         #<Set: {2, -2}>,
# =>         #<Set: {-4}>,
# =>         #<Set: {3}>}>

标签:Ruby,集合

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2016-04-24 14:16:11Create Your stack by Loli控
  2. 2016-08-28 09:48:44extend Forwardable by 好好学习啊
  3. 2016-08-28 13:39:21Add set operation to Array by 永明
  4. 2016-09-03 12:08:57Writing Block Methods that Classify or Collect by Jamin
  5. 2016-11-19 09:06:23Building a Histogram by Ω油菜
  6. 2015-12-19 11:02:24Custom class based range by JustForFly
  7. 2016-01-16 09:59:29Sort with block by 胡晋
  8. 2016-01-20 16:52:19Each loop by zetaliang
  9. 2016-08-28 10:10:01Create set with Set.new by LeoSun
  10. 2016-08-28 13:57:54inorder / preorder / postorder by 永明
  11. 2016-09-16 19:29:52Classify a set into three by 永明

发表评论