Assuming I have an array or arrays:
arr = [["Foo1", "Bar1", "1", "W"],
["Foo2", "Bar2", "2", "X"],
["Foo3", "Bar3", "3", "Y"],
["Foo4", "Bar4", "4", "Z"],
["Foo5", "Bar5", "5", "A"]]
Is there a way I can move an individual array in the 2d array based on some criteria?
For example, if element 3 of the inner array is "4", then move it to the top?
So the above arr would then look like:
[["Foo4", "Bar4", "4", "Z"],
["Foo1", "Bar1", "1", "W"],
["Foo2", "Bar2", "2", "X"],
["Foo3", "Bar3", "3", "Y"],
["Foo5", "Bar5", "5", "A"]]
I have tried things like to try and select the inner array:
arr.map {|row| row.select {|i| i[3] == "4"} }