From: Craig Law Date: 2012-06-18T10:56:43+09:00 Subject: Re: Overwriting one Ruby array or arrays with another Can anyone help me with ordering a hash that's being converted to an array. As above I've followed Martin's suggestion and converted two array's into hashes, merged the hashes and I'm attempting to convert them back into an array. Current hash looks like this ... [[1, 3]=>["X","20120609"], [3, 3]=>["X","20120610"], [2, 1]=>["X","20120611"], [1, 2]=>["X","20120612"], [3, 2]=>["X","20120613"], [3, 1]=>["X","20120614"], [1, 3]=>["X","20120615"], [2, 1]=>["X","20120616"], [2, 2]=>["X","20120617"]] As you can see the x, y coordinates are in a random order and I need to convert the above hash back into an array that looks like this ... [[1, 3, "X","20120609"], [2, 3, "X","20120610"], [3, 3, "X","20120611"], [1, 2, "X","20120612"], [2, 2, "X","20120613"], [3, 2, "X","20120614"], [1, 1, "X","20120615"], [2, 1, "X","20120616"], [3, 1, "X","20120617"]] Basically I need to order the x coordinate first in ascending order and the y coordinate second in descending order. The command I've mucked around with that Martin posted above is ... c = hash1.keys.sort.map {|k| [k[0],k[1]] + hash1[k]} ... but that's giving me y coordinates ordered first in ascending order and x coordinates ordered second in ascending order like this ... [[1, 1, "X","20120609"], [1, 2, "X","20120610"], [1, 3, "X","20120611"], [2, 1, "X","20120612"], [2, 2, "X","20120613"], [2, 3, "X","20120614"], [3, 1, "X","20120615"], [3, 2, "X","20120616"], [3, 3, "X","20120617"]] Has anyone got any suggestions on how I can achieve an ordered array that looks like this ... [[1, 3, "X","20120609"], [2, 3, "X","20120610"], [3, 3, "X","20120611"], [1, 2, "X","20120612"], [2, 2, "X","20120613"], [3, 2, "X","20120614"], [1, 1, "X","20120615"], [2, 1, "X","20120616"], [3, 1, "X","20120617"]] Many thanks Craig -- Posted via http://www.ruby-forum.com/.