I am trying to compare two arrays to ensure that the corresponding values of one are always greater than the others.
a = [2, 3, 4]
b = [1, 2, 3]
At this point, I am thinking of using injectwith an index and returning if the comparison fails, for example:
b.each_with_index.inject(true) do |cmp, (element,index)|
if element > a[index] do
cmp = false
return
end
end
Is there a better way to do this? A feeling similar to Ruby or Rails may already have something like this inline, and I skipped it.
source
share