Consider this array.
[1, 2, 2, 2, 3, 4, 4, 5]
I would like to sort this array in the order of how many times a certain element value exist.
So in the case above the value 2
exist three times, therefore these should come first. Followed by the two instances of 4
, and then last 1, 3, 5
.
[2, 2, 2, 4, 4, 1, 3, 5]