in reply to sort an array according to another array

The problem is that you are stuck with lookups into the larger array and that's O(n). Your best choice if you have to do this a lot and the larger array isn't so large that memory usage would make it unfeasible, would be to make a hash keyed by the elements in the larger array where the values are those elements' indexes. Otherwise, what you are doing is pretty reasonable.

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: sort an array according to another array