Here is an example:
// 0 1 2 3 4
var people = ['jack','jill','nancy','tom','cartman'];
var order = [3,1,4,0,2];
// somehow sort people array to the order specified in the order array
// 3 1 4 0 2
people == ['tom','jill','cartman','jack','nancy'];
I have used .sort with a function before, but am still at a loss on this one.
UPDATE
after seeing some answers, I can't believe this was not obvious to me. So as there are many ways to do this, winner will be determined by jsperf.
(also I am upvoting everyone with a working answer)
people
variable, you're only updating that one reference. If there are other references to the original Array, they won't automatically be updated to reference the new Array, so your references will be out of sync. All depends on what's needed. – I Hate Lazy Oct 30 '12 at 23:47