I have an array of ids
a1 = [1, 2, 3, 4, 5]
and I have another array of objects with ids in random order
a2 = [(obj_w
Inspired by Eric Woodruff's Answer, I came up with the following vanilla Ruby solution:
a2.group_by(&:object_id).values_at(*a1).flatten(1)
Method documentation: