the method .debug just prints the contents of a variable to the post window with a user defined prefix
I had assumed that your “ordering” array was an array of increasing numbers, used only to determine the reordering of elements. But apparently this is not what you want.
Using the .order method (which is less typing work than the decorate-undecorate method)
(
var elements = ["nora", "andre", "nel", "ipsy", "liam"].debug("elements");
var other_array = [100, 200, 300, 400, 500].debug("other_array");
var elements_order = elements.order({ |a, b| a < b }).debug("elements_order");
var elements_sorted = elements.sort({ |a, b| a < b }).debug("elements_sorted");
var other_array_resorted = elements_order.collect({|el| other_array[el] }).debug("other_array_resorted");
)
output
elements: [ nora, andre, nel, ipsy, liam ]
other_array: [ 100, 200, 300, 400, 500 ]
elements_order: [ 1, 3, 4, 2, 0 ]
elements_sorted: [ andre, ipsy, liam, nel, nora ]
other_array_resorted: [ 200, 400, 500, 300, 100 ]
-> nil