The proper way to exploitUsing Odering
(assuming that ref
and set
are of same length):
set[[Ordering@Ordering@ref]]
or a more complicated, less efficient way is:
pos = Range@Length@set;
set[[pos /. Thread[Ordering@ref -> pos]]]
{"E", "A", "D", "C", "B"}
MoreAn even more complicated way to do the same:
ref = {"e", "a", "d", "c", "b"};
set = {"A", "B", "C", "D", "E"};
order = Position[Sort@ref, #, 1][[1, 1]] & /@ ref
{5, 1, 4, 3, 2}
set[[order]]
{"E", "A", "D", "C", "B"}