I have an array that looks like this:
[ { type: 'A', price: '0.01' }, { type: 'B', price: '4.23' }, { type: 'D', price: '2.29' }, { type: 'B', price: '3.38' }, { type: 'C', price: '1.15' } ]
I need to group them with type and then sort them in ascending price . I can solve this problem in half by following these steps:
boards.sort_by {|e| [e['type'], e['price'].to_f]}
Unfortunately, this sorts type in alphabetical order when they should be sorted by BADC
How to sort an array according to predefined rules?
sorting ruby
purinkle
source share