Last active
August 29, 2015 14:13
-
-
Save tuscen/6711d3baf77d1bdc6d08 to your computer and use it in GitHub Desktop.
This file contains 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
def conjunctionSelect obj,arg,*args | |
res = [] | |
for i in obj | |
res << i if ([arg]+args).inject do |acc,n| | |
n.call(i) && acc.call(i) | |
end | |
#res << i if ([arg]+args).all? {|n| n.call(i)} | |
end | |
res | |
end | |
class Array | |
def all? | |
if block_given? then | |
self.inject do |acc,i| | |
yield(acc) && yield(i) | |
end | |
else | |
self.inject do |acc,i| | |
acc && i | |
end | |
end | |
end | |
def any? &b | |
unless b then | |
self.inject do |acc,i| | |
acc || i | |
end | |
else | |
self.inject do |acc,i| | |
b.call(acc) || b.call(i) | |
end | |
end | |
end | |
end | |
p [-1,9,1].any?{|i| i>0} | |
p [1,2,3,-6].all?{|i|i<0} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment