I have two arrays like this: arr1 = [name1, name2,name3] and arr2 = [[name1,10], [name3,15], [name2, 20]]. Now I want to sort the arr2 based on the order of arr1. The order of arr2 will change whenever order of arr1 change. I try this:
hash_object = arr2.each_with_object({}) do |obj, hash|
hash[obj.name] = obj
end
arr1.map { |index| hash_object[index] }
But the result returned [nil, nil, nil]. I confused of this is the right way, and I only made mistake or are there another ways to solve my problem. Can someone help me?