Hi,
let's say I have the following array:
arr = [[5,1], [2,7]]
and I want to find the minimum comparing the second element. i.e. The minimum will be [5,1] (since 1 is less than 7). I can use the following code:
arr.min {|a,b| a[1] <=> b[1]}
For calculating the maximum I can do the same:
arr.max {|a,b| a[1] <=> b[1]}
That gives [2,7]. Now, what I do not want is repeat myself since I am basically given all the time the same block. I would like to have that block somewhere and provide it to the min/max function. I hoped something like:
blo = lambda {|a,b| a[1] <=> b[1]}
arr.min blo
but didn't really work... so didn't work any of the other things I tried. Any Idea on how can I do this?