def order_of_letters(text) sorted = text.chars.sort.join #use only this one if you want just sorted arr of letters result = [] text.split('').each do |symbol| result << sorted.index(symbol).to_i end result end