This gives your sample output for sample input, so hopefully this is what you want (it sorts the values of each subarray in the first array by the value in the same position in the corresponding subarray of the second array, in descending order):
class Array def sort_by_other_array(arr) zip(arr).sort_by {|x,y| y}.map {|x,y| x} end end a=[[1,2,3],[4,5]] b=[[2.5,1.5,3.5],[1.5,2.5]] a.zip(b).map {|x,y| x.sort_by_other_array(y).reverse} #=> [[3, 1, 2], [5, 4]]
source share