This seems pretty straightforward and should have been asked before, but everything I find in Stack Overflow doesn't seem to work. I have an array of 4 objects, and I would like to reorder it in a specific order. So it looks like this:
array = [Obj1, Obj2, Obj3, Obj4]
I have another array of integers that represent the desired index order:
desired_order = [2,3,0,1]
So, I would like the array be correct after ordering:
array = [Obj3, Obj4, Obj1, Obj2]
I already realized that sort_by is a method to use, but I cannot come up with the correct syntax. Any help is much appreciated!
source share