arr = [1,2,1,3,5,2,4]
How can I count the array by group value with sorting? I need the following output:
x[1] = 2 x[2] = 2 x[3] = 1 x[4] = 1 x[5] = 1
x = arr.inject(Hash.new(0)) { |h, e| h[e] += 1 ; h }
2.1m questions
2.1m answers
60 comments
57.0k users