I have an array of array as below:
a = [
["a", "v", 1], ["b", "w", 2], ["c", "x", 1], ["d", "y", 1],
["e", "z", 2], ["f", "one" , 3 ], ["g", "two" , 3 ], ["g", "one" , 4 ],
["f", "one" , 1 ], ["h", "one" , 5 ], ["f", "one" , 4 ],
# ...
]
Then , i expect the result as 5 different arrays
a1 = [ ["a", "v", 1],["c", "x", 1], ["d", "y", 1], ["f", "one" , 1 ] ]
a2 = [ ["b", "w", 2], ["e", "z", 2] ]
a3 = [ ["f", "one", 3], ["g", "two", 3] ]
a4 = [ ["g", "one", 4], ["f", "one", 4] ]
a5 = [ ["h", "one" , 5 ] ]
# ...
an = []
By doing the below code, i was able to sort it.
b = a.sort{|c,d|c[2] <=> d[2]}
How can i generate such a list.
Please help.Thanks in advance.