Created
December 12, 2011 19:23
-
-
Save squarism/1468671 to your computer and use it in GitHub Desktop.
Reject without reject
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [10, 20, 30, 40, 50] | |
# each stage along the way: | |
# >> a.each_with_index.collect {|value,index| {index => value <= 30} } | |
# => [{0=>true}, {1=>true}, {2=>true}, {3=>false}, {4=>false}] | |
# | |
# .select {|h| h.invert.has_key?(false) } | |
# => [{3=>false}, {4=>false}] | |
# | |
# .collect {|h| h.keys}.flatten | |
# => [3, 4] | |
a.each_with_index.collect {|value,index| {index => value <= 30} } \ | |
.select {|h| h.invert.has_key?(false) } \ | |
.collect {|h| h.keys}.flatten | |
# => [3, 4] | |
# meh have to go over index again. :( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment