Ruby String Exercises: Sort a string's characters alphabetically
Ruby String: Exercise-11 with Solution
Write a Ruby program to sort a string's characters alphabetically.
Ruby Code:
def check_string(str)
return str.chars.sort.join
end
print check_string("javascript")
print "\n",check_string("python")
print "\n",check_string("PHP")
Output:
aacijprstv hnopty HPP
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to count the occurrences of a specified character in a given string.
Next: Write a Ruby program to remove a specified character into a given string.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/ruby-exercises/string/ruby-string-exercise-11.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics