Skip to content

Instantly share code, notes, and snippets.

@squarism
Created December 12, 2011 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squarism/1468671 to your computer and use it in GitHub Desktop.
Save squarism/1468671 to your computer and use it in GitHub Desktop.
Reject without reject
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