I was looking for a way to sort an array using another array. Here was an answer that worked for me:
- The order_array (an array of ids in a weird order that I want):
a1 = [34, 54, 12, 43]
- The list of objects (that I want to order):
a2 = [ {id: 54, name: "greg"}, {...}, {...}, {...} ]
a2.sort_by{|x| a1.index x.id}
What is going on with this little piece of code?