返回顶部

收藏

Divide a set by even and odd value

更多
require 'set'
s = Set.new((1..10).collect)

# Divide the set into the '0' subset and the '1' subset: that is, the
# 'even' subset and the 'odd' subset.
p s.divide { |x| x % 2 }
# => #<Set: {#<Set: {6, 2, 8, 4, 10}>, #<Set: {5, 1, 7, 3, 9}>}>

标签:Ruby,集合

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2015-12-06 21:03:01Set length, size and empty? by LeoSun
  2. 2016-08-28 09:17:16Implementing Enumerable - Write One Method, Get 22 Free by digua
  3. 2016-08-28 12:59:01Divide a set by its element's class by 胡晋
  4. 2016-02-04 11:37:45Collect in place by 永明
  5. 2016-04-24 14:08:00Map elements in a set by digua
  6. 2016-08-28 09:29:05Sort on two arrays by jeffsui
  7. 2016-08-28 13:17:44Convert a hash to set and divide by zetaliang
  8. 2016-09-20 09:21:04Divide a set by absolute value by 好好学习啊
  9. 2016-04-24 14:16:11Create Your stack by Loli控
  10. 2016-08-28 09:48:44extend Forwardable by 好好学习啊
  11. 2016-08-28 13:39:21Add set operation to Array by 永明

发表评论