1

I have a array of hash something like

[{a1: 'a', b1: 'b'},{a1: 'c', b1: 'b'},{a1: 's', b1: 'cq'}]

I want to sort the array in the ascending value of b1 and return an array. Sorry if its easy but got confuse with the logic.

rekha
  • 27
  • 3
  • This is a pure-Ruby question, so you should remove the Rails tags (even though it's been marked as a duplicate). When you give an example, please assign a variable to each input (e.g., `arr = [{a1:....]`) so that readers can refer to those variables in comments and answers without having to define them. Also, show your desired output for the example's input data. – Cary Swoveland Feb 09 '17 at 18:00

1 Answers1

0

Following will return you an array sorted based on b1

array_of_hashes.sort_by { |hsh| hsh[:b1] }
Sapna Jindal
  • 412
  • 3
  • 11