I need to sort a multidimensional array by first line. The first line (array[0][0] to array[0][n-1]) is composed of strings, I need to sort it, and the other lines to follow up...
I already searched a lot and saw how to use the sort function to sort it by column, but didn't found out how to apply it to my problem...
I already solved my problem with a bubble sort who sort the first line, then report the change to the other lines if there's one, but I wondered if there was a better way to do it ?
Creation of the array :
array = Array.new(4) { Array.new(var, 0) }
I have something like that in it :
[ [ "A 1", "A 3", "A 2", "A 4" ],
[ 4, 5, 6, 7 ],
[ 2, 2, 2, 2 ],
[ 0.1, 0.2, 0.1, 0.2 ] ]
The expected result would be as followed :
[ [ "A 1", "A 2", "A 3", "A 4" ],
[ 4, 6, 5, 7 ],
[ 2, 2, 2, 2 ],
[ 0.1, 0.1, 0.2, 0.2 ] ]