This code works very well:
def is_rel_prime?(*args) #1
test = args.combination(2).to_a #2
test.map! { |a,b| a == Rational(a,b).numerator } #3
test.reduce (:&) #4
end
> is_rel_prime?(3,4,5) #=> true
> is_rel_prime?(7,12,14) #=> false
> is_rel_prime?(7,12,15) #=> false
What do I replace the (:&) with so that it will return 'true' if ANY ONE (or more) of the array elements is 'true'?
test.any?or drop that line and changetest.map!...to:test.map { |a,b| a == Rational(a,b).numerator }.any?(no need for !).test.any?returnstrueif any element oftestis "thruthy" (neithernilnorfalse); else returnsfalse.args.combination(2).any? { |a,b| a == Rational(a,b).numerator }