I have no idea how to formulate the question correctly, but what I want is the following:
Let's say there's an array like
[1,1,1,1,2,2,2,3,3,3,4,4,5]
How can I sort it, until this becomes the output:
[1,2,3,4,5,1,2,3,4,1,2,3,1]
To make the output a bit more readable:
[[1,2,3,4,5],[1,2,3,4],[1,2,3],[1]]
What I've come up so far is:
array = [1,1,1,1,2,2,2,3,3,3,4,4,5]
array.group_by{|n| n }.values.transpose.flatten
But this throws an error due to not having the same amount of numbers.
Can anybody help?