Question

I want to short this array's arry by second element that is like "06" then `"00". "00" should come first in rows

[
    ["new  ", "06"],
    ["one ", "00"],
    ["old  ", "07"],
    ["change  ", "16"] ,
    ["greate ", "08"],
    ["ok  ", "50"],
    ["done  ", "09"]
]
Was it helpful?

Solution

Does this work out as you want?

array.sort { |x,y| x[1] <=> y[1] }
=> [["one ", "00"], ["new  ", "06"], ["old  ", "07"], ["greate ", "08"], ["done  ", "09"], ["change  ", "16"], ["ok  ", "50"]]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top