How to sort characters in string in Ruby

2 Answers

0 votes
def sort_string(s)
    array = s.split ""
    array.sort!
    s = array.join
    return s
end



puts(sort_string("ruby"))




# run:
#
# bruy
#

 



answered Nov 7, 2020 by avibootz
0 votes
s = "ruby"

s = s.chars.sort.join
   
puts s




# run:
#
# bruy
#

 



answered Nov 7, 2020 by avibootz

Related questions

...