So are you saying that if you have an array like:
a = [‘d’, ‘b’, ‘a’, ‘c’, ‘e’]
You would like to get something like:
a.sort_index #=> [2, 1, 3, 0, 4]If that’s the case, then I’m sure it’s doable. No built-in
method that I’m
aware of, but you could easily create one.
For example:
class Array
def sort_index
(0…size).sort_by {|i| self[i]}
end
end
%w{d b a c e}.sort_index
=> [2, 1, 3, 0, 4]