Say I'm given a string array, each string has a corresponding weight. So for example:
str_arr = ["james", "blake", "rob"]
weights = [4, 7, 1]
str_arr[i] corresponds to weights[i].
How would I go about sorting str_arr in ascending order with respect to weights? For example:
(after sorting) weights would be [1, 4, 7] which corresponds to str_arr = ["rob", "james", "blake"]
How do I get ["rob", "james", "blake"]?
Most sorting comparators deal with modifying the way the sorting on the current array works, and I looked into sorting with respect to the existing order of a different array--but I'm not sure how to sort the integer array and simultaneously do the same with the str_arr based on the output of the integer array...Is there a Rubyist way of doing this?