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
hash_object = objects.each_with_object({}) do |obj, hash| hash[obj.object_id] = obj end [1, 2, 3, 4, 5].map { |index| hash_object[index] } #=> array of objects in id's order
I believe that the run time will be O(n)